日期:2014-05-18  浏览次数:20514 次

问一个语句
2表t1,t2
t1
col1
a
b
c
-------
t2
col1
b
a
c
如何知道这2个表查询结果是相等的.

------解决方案--------------------
----返回1则表示完全相同,返回0 则表示不完全相同
select
case
when (select checksum(*) from t1) = (select checksum(*) from t2)
then 1
else 0
end

------解决方案--------------------
select '相等 '
where exists(
select 1
from t1
full join t2 on t1.col1 = t2.col1
where t1.col1 is null or t2.col1 is null
)
------解决方案--------------------
1. 返回的行数相等
2. 两个表关联后的行数和步骤1的行数一致
------解决方案--------------------
一两的不对吧,(select checksum(*) from t1)返回的是一个结果集啊
------解决方案--------------------
select * from t1 where col1 not in (select col1 from t2)
select * from t2 where col1 not in (select col1 from t1)

两个都没结果就对了
------解决方案--------------------
SELECT EQUAL = (CASE WHEN NOT EXISTS(SELECT 1 FROM t1 WHERE col1 NOT IN (SELECT col1 FROM t2)) AND NOT EXISTS(SELECT 1 FROM t2 WHERE col1 NOT IN (SELECT col1 FROM t1)) THEN 'YES ' ELSE 'NO ' END)