基于列的Sql查询条件可以保持位

时间:2012-11-11 08:55:25

标签: sql sql-server

我的问题是:

select
    ProdID, Qualified 
from 
    VarAnn_Data.dbo.tblOwnership

程序输出:

ProdID(num) Qual (Bit)
26  0
26  0
26  1
26  0
26  1
26  0
26  0
27  0
28  0
28  0
28  0
28  0
28  0
28  1
28  1
29  0
29  0
29  1
29  0
29  1
29  0
29  0

现在单个prodid有多个零。我得到了明显的结果

案例1:

ProdId(num)      Quak(bit)
26                  0
26                  1

结果:A

ProdId(num)      Quak(bit)
26                  0

结果:B

ProdId(num)      Quak(bit)
26                  1

结果:C

1 个答案:

答案 0 :(得分:1)

这是你在找什么?

select ProdID, 
       min(Qualified),
       case when min(Qualified) <> max(Qualified) 
            then 'YES'
            else 'NO'
       end as Has_different_results
from VarAnn_Data.dbo.tblOwnership
group by ProdID