求SQL语句,当B列等于某值时,结果不取A列的值 例表:A列 B列100 -1100 21200 -1当B列里有21时,不取A列的100结果:A列 B列200 -1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from tb where b <> 21 select (case when b=21 then 默认值 else a end) a,b from tb 这问题表达的太不清楚了。难道是这意思?select * from tb where a not in(select distinct a from tb where b=21) --例表:--A列 B列--100 -1--100 21--200 -1--当B列里有21时,不取A列的100--结果:--A列 B列--200 -1declare @t table(A列 int ,B列 int )insert into @t values( 100,-1)insert into @t values( 100,21)insert into @t values( 200,-1) select A列,B列 from @t where A列<>100 AND (select COUNT( A列 )from @t where B列=21)>0A列 B列----------- -----------200 -1(1 行受影响) A列没有要求等于或不等于某值这样说吧,我是要查找 当A列相同的情况下,B列里不包含21的结果,只要B列里有21了,A列有相同值了也不显示 select * from table1 where b<>21 那就是这个啊!select * from tb where a not in(select distinct a from tb where b=21)还不是的话。你多给几行测试数据,和想要的结果。用文字表达,不如用数据表达。 求SQL 语句 SQL SERVER 如何建立定时作业?谁有相关的脚本? 请问,text,varchar(8000)这样的字段还没值时占用实际硬盘空间吗? 能不能从一个表中,根据字段的序号,取出该列的值呢? 修改字段的问题 请问高手personal版本是不是不能和jdbc连接? 请教一个修改表的设计来提高查询效率的问题 reporting service 无法连接数据库,请帮忙看看 tempdb系統資料庫中暫存資料表 究竟数据挖掘是不是在数据库里面挖掘数据放到数据仓库? 请问各位大神,培训类新闻网站的数据库应该如何设计? 谁有考勤管理的报表查询语句
select * from tb where a not in(select distinct a from tb where b=21)
--A列 B列
--100 -1
--100 21
--200 -1--当B列里有21时,不取A列的100--结果:
--A列 B列
--200 -1
declare @t table(A列 int ,B列 int )
insert into @t values( 100,-1)
insert into @t values( 100,21)
insert into @t values( 200,-1)
select A列,B列 from @t where A列<>100 AND (select COUNT( A列 )from @t where B列=21)>0A列 B列
----------- -----------
200 -1(1 行受影响)
还不是的话。你多给几行测试数据,和想要的结果。用文字表达,不如用数据表达。