这个语句的结果是:计算机系并且年龄大于19岁的学生
不就是计算机系的减去年龄不大于19岁的差集嘛
用minus可以这样写:
select Sno from student where Sdept = 'CS'
minus
select Sno from student where Sage <= 19
注意这里必须写出明确的列,不能用*, 而且字段要相对应
原
SQL集合运算:差集、交集、并集
2011年03月30日 15:41:00
阅读数:15446
1、差集( except )
select a from t_a
except
select a from t_b
-- 也可写作:
select a from t_a where a not in (select a from t_b)
-- 多个字段时:
select a,b from t_a
except
select a,b from t_b
-- 多字段的查集也可写成:
select a,b from t_a where (a,b) not in (select a,b from t_b)
2、交集( intersect )
select a from t_a
intersect
select a from t_b
-- 也可写作:
select a from t_a where a in (select a from t_b)
3、并集( union )
select a from t_a
union distinct
select a from t_b
差集对应数据库 *** 作应该是select from a where a not in (select from b)对于内存数据(比如dataTable 或是数组)比较
linq的办法大致 a.Where(rowA=>!b.Any(rowB=>rowB==rowA))
即可获得a-b的结果集
使用Except的linq扩展 还是自己写比较器的好
或者 你可以先把dataRow先select映射到某一列 成为.net基础类型的集合 再进行比较
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)