某个表 有两个字段 字段A和字段B 数据如下
(8,11)
(8,12)
(9,10)
(9,11)
(9,12)
(10,8)
(10,10)
(11,10)
(11,12)
(11,13)
要求查询同一个字段A时候 字段B符合10 12此时 全部字段A含有的字段 表达不是很清楚
sql的写法是 select * from TB as X
where not exists(select * from TB as Y where (Y.b = '1' or Y.b = '2') and not exists(select * from TB as Z where Z.a = X.a and Z.b = Y.b));
使用了exists 字句 exists字句主要提供一个boolen 如果是true就显示 如果是false就不显示 not exists相反
发表评论