MSSQL中2个搜索结果集相减如何实现?
发布网友
发布时间:2022-09-13 11:28
我来回答
共3个回答
热心网友
时间:2024-11-15 19:44
select * into #temp1 from table1 where 条件1
select * into #temp2 from table1 where 条件2
select * from #temp1 where id not in (select id from #temp2 )
或者不考虑效率,直接写成
select * from tale1 where id not in (select id from tabel1 where 条件2) and 条件1
热心网友
时间:2024-11-15 19:44
花了10分钟终于写好了
试试看
declare @mytest int,@mytest2 int,@mytest3 int
set @mytest=(select sum(stdnum) from table1 where times=1)
set @mytest2=(select sum(stdnum) from table1 where times=2)
set @mytest3=abs(@mytest-@mytest2)
select * from table1 where stdnum=@mytest3
热心网友
时间:2024-11-15 19:45
为什么不这样检索呢
select * from table1 where times=1 and times<>2