求这样的sql语句 select a.id ,a.pid,a.cid ,[istb]=(case exists(select * from a,b where a.id=b.id and a.pid=b.pid) then 1 else 0 end ) from a ; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 declare @a table([id] int,pid int,cid int)declare @b table([id] int,pid int,cid int)insert @aselect 1,7,5 [union] allselect 1,8,5 [union] allselect 1,10,5 [union] allselect 1,21,5 [union] allselect 1,7,6 [union] allselect 1,6,6 insert @bselect 1,7,5 [union] allselect 1,8,5 [union] allselect 1,7,6 [union] allselect 1,6,6 select a.*,istb=case when a.pid=b.pid then 1 else 0 endfrom @a aleft join @b b on b.[pid]=a.[pid] and b.cid=a.cidid pid cid istb ----------- ----------- ----------- ----------- 1 7 5 11 8 5 11 10 5 01 21 5 01 7 6 11 6 6 1(所影响的行数为 6 行) 十分感谢,分不够抱歉了,csdn让我学到好多,感谢大侠们 select a.id ,a.pid,a.cid ,[istb]=(case (select 1 from a,b where a.id=b.id and a.pid=b.pid)>0 then 1 else 0 end ) from a select a.id ,a.pid,a.cid ,case b.id isnull then 0 else 1 end from a left join b on a.id=b.id 关于timestamp类型数据的更新 求句 语法问题 版主,我的贴子怎么会是这样? 列内容取整问题 ■■■■■这样的条件统计SQL语句该怎么写,条件比较复杂!! sql server 2000安装问题 请问如何用Delphi在SQL Server中创建一个数据库,并把源有某数据库数据复制到该数据库? 能使您充分发挥创造力的通用信息管理软件 关于SQL7.0一问 SQL server 2012 包含数据库参数设定 关于date和image数据类型 请问如何改变Identity字段的标识种子的初始值?(使用T-SQL)
([id] int,pid int,cid int)declare @b table
([id] int,pid int,cid int)insert @a
select 1,7,5 [union] all
select 1,8,5 [union] all
select 1,10,5 [union] all
select 1,21,5 [union] all
select 1,7,6 [union] all
select 1,6,6 insert @b
select 1,7,5 [union] all
select 1,8,5 [union] all
select 1,7,6 [union] all
select 1,6,6 select a.*,istb=case when a.pid=b.pid then 1 else 0 end
from @a a
left join @b b on b.[pid]=a.[pid] and b.cid=a.cid
id pid cid istb
----------- ----------- ----------- -----------
1 7 5 1
1 8 5 1
1 10 5 0
1 21 5 0
1 7 6 1
1 6 6 1(所影响的行数为 6 行)
a.pid=b.pid)>0 then 1 else 0 end ) from a