首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问一个SQL语句写法

2012-03-14 
请教一个SQL语句写法。一个表中有一个bit类型的段,和一个ItemID(可以重复),现在根据ItemId返回多条记录,要

请教一个SQL语句写法。
一个表中有一个bit   类型的段,和一个ItemID(可以重复),现在根据ItemId返回多条记录,要检测记录当其中所有bit型的字段都为真时,   as   一个字段为真,不用遍历,有什么语句或方法?

[解决办法]

select * from ta a
where ItemID=....
and
not exists(select 1 from ta where ItemID=a.ItemID and [bit]=0 )

[解决办法]
ItemID=....--指定条件(要取的ItemID)

不指定时,把所有满足的都选出来
select * from ta a
where
not exists(select 1 from ta where ItemID=a.ItemID and [bit]=0 )
[解决办法]
select (case when count(a)=sum(a) then 1 else 0) as '一个字段为真 '
from 表 where idtmid=条件
没考虑bit为null时

热点排行