0

我有一列值来自 0、1、2 见下文

0 = no, 1 = yes and 2 is waiting

我只想显示是否的计数并在哪里等待adminid=1468

 IsVerified        AdminId
    0               1468
    0               1475  
    1               1468 
    1               1468
    1               1468 
    1               1468 
    1               1475
    2               1468
    2               1466

我想将其显示为adminid=1468

No    Yes    Waiting   AdminId
1      4       1        1468

到目前为止,我已经使用

SELECT     
    COUNT(s.IsVerified) AS [Yes]
    ,COUNT(s.IsVerified) AS [No]
    ,COUNT(s.IsVerified) AS [Waiting]
    ,g.AdminId
FROM    
    tbl_Squad s, tbl_Match m, tbl_Group g
WHERE   
    m.GroupId = g.GroupId          
    --AND g.AdminId=@AdminId
    AND g.AdminId=1468          
GROUP BY         
    s.IsVerified

但它给出了三行,而我只想要一行我错了

4

2 回答 2

3

像这样的东西应该工作:

select sum(case when s.isverified = 0 then 1 else 0 end) no
, sum(case when s.isverified = 1 then 1 else 0 end) yes
, sum(case when s.isverified = 2 then 1 else 0 end) waiting

from tbl_squad s join tbl_group g on s.groupid = g.groupid

where g.adminid = 1468
于 2013-06-16T12:18:30.110 回答
1
select SUM(case when s.IsVerified= 0 then 1 else 0 end) as No
, SUM(case when s.IsVerified= 1 then 1 else 0 end) as Yes
, SUM(case when s.IsVerified= 2 then 1 else 0 end) as Waiting
,g.AdminId

from tbl_Squad s join tbl_Group g on s.GroupId = g.GroupId

where --g.adminId=@AdminId
      g.AdminId= 1468
group by g.AdminId
于 2013-06-16T12:22:04.957 回答