求SQL语句,当B列等于某值时,结果不取A列的值
例表:
A列 B列
100 -1
100 21
200 -1
当B列里有21时,不取A列的100
结果:
A列 B列
200 -1
[解决办法]
这问题表达的太不清楚了。难道是这意思?
select * from tb where a not in(select distinct a from tb where b=21)
发布时间: 2012-03-12 12:45:33 作者: rapoo
求SQL语句,当B列等于某值时,结果不取A列的值
例表:
A列 B列
100 -1
100 21
200 -1
当B列里有21时,不取A列的100
结果:
A列 B列
200 -1
[解决办法]
这问题表达的太不清楚了。难道是这意思?
select * from tb where a not in(select distinct a from tb where b=21)