高手帮忙,查询写了一半,下面的不会了

kevinnick kevinnick 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有一表oitm,有一列的数据为:fcc090101a,fcc090102a,fcc090103a,fcc090106a,fcc090107a,fcc090110a.....
现在要把数据分离为 101,102,103,106,107,110.....
然后列出其中缺少的数字 104,105,108,109


请问这个查询要如何做呢?

我的想法是把 101,102,103,106,107,110等分离出来写到表 #tt里面,
然后生成另一个临时表#tst,数据为 101,102,103,104,105,106,107,108,109,110
然后比较,其中缺少的就是了,但是我写了一半,下面的不会写了,高手帮忙。。。。

if OBJECT_ID('tempdb..#tt') is not NULL
drop table #tt

select distinct convert(int,SUBSTRING(ItemCode,7,3)) as substr
into #tt
from OITM
where ItemCode between 'fcc090101a' and 'fcc091010a'

declare @start int
declare @end int
select @start = min(substr),@end = max(substr)
from #tt

if OBJECT_ID('tempdb..#tst') is not NULL
drop table #tst


...全文
评论 12
收藏 已收藏
分享
返回顶部
kevinnick
应用实例 27,579 成员 68,540 内容