同一个表,两个语句,需要两者之间的区别

问题描述 投票:0回答:2

我是一名英语专业学生,在我非常基本的SQL Stuff中磕磕绊绊。我已经得到了两个语句来返回我需要的结果(都来自同一个表):

select *
from Table1
where Column1 = 'Examplel' and UniqueID is not null
order by UniqueID2

(返回2000行)

select *
from Table1
where Column1 = 'Examplel'
and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000'
order by UniqueID2

(2001年回归)

我需要找到一条差异线,优先不滚动并比较两个结果中的所有线。救命?

sql difference
2个回答
1
投票

将此全部作为一个语句运行:

select * from Table1 where Column1 = 'Examplel' and UniqueID is not null order by UniqueID2

except

select * from Table1 where Column1 = 'Examplel' and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000' order by UniqueID2

然后反过来:

select * from Table1 where Column1 = 'Examplel' and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000' order by UniqueID2

except

select * from Table1 where Column1 = 'Examplel' and UniqueID is not null order by UniqueID2

1
投票
select *
from Table1
where Column1 = 'Examplel'
and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000
and UniqueID is null
order by UniqueID2
© www.soinside.com 2019 - 2024. All rights reserved.