0

我正在尝试计算通过和失败的设备我有我想要的所有数字,但它们并不完全正确。

例如:

select 
    t3.displayname as [PSI], 
    case when t0.compliant = 0 then count(displayname) end as [failures],
    case when t0.compliant = 1 then count(displayname) end as [success]
from lineitemsmap as t0
    inner join art_blob as t1 on t1.art_blob_id = t0.blobid
    inner join art_asset as t2 on t2.art_asset_id = t1.art_asset_id
    inner join net_ou as t3 on t3.net_ouid = t2.net_ouid
group by t3.displayname, t0.compliant

生成:

------------------------------
| PSI | failures | success   |
------------------------------
| 1   | 3        | NULL      |
------------------------------
| 2   | 4        | NULL      |
------------------------------
| 3   | 5        | NULL      |
------------------------------
| 1   | NULL     | 6         |
------------------------------
| 2   | NULL     | 7         |
------------------------------
| 3   | NULL     | 8         |
------------------------------

我试图让所有结果在 3 行第 6 节中返回。

4

1 回答 1

2
select 
    t3.displayname as [PSI], 
    SUM(case when t0.compliant = 0 then 1 else 0 end) as [failures],
    SUM(case when t0.compliant = 1 then 1 else 0 end) as [success]
from lineitemsmap as t0
    inner join art_blob as t1 on t1.art_blob_id = t0.blobid
    inner join art_asset as t2 on t2.art_asset_id = t1.art_asset_id
    inner join net_ou as t3 on t3.net_ouid = t2.net_ouid
group by t3.displayname;
于 2012-07-18T16:25:48.450 回答