我試圖改進以前寫的查詢。這是查詢 -這些查詢有什麼不同?
select tq.feature as Feature, tq.Total, pq.Passed
from (
select feature, count(distinct id) as Total
from X.results
where ver = '4.2'
group by feature
) as tq
LEFT JOIN (
select feature, count(distinct id) as Passed
from X.results
where ver = '4.2' and result = 'pass'
group by feature
) as pq USING (feature);
這是我寫的查詢。但結果似乎是不同的.Am在這裏丟失的東西?
select feature,count(distinct id) as totalcases,
sum(case when result = 'PASS' then 1 else 0 end) as passed
from X.results
where ver='4.2'
group by feature
order by feature;
我在SQL一個真實的小白所以請原諒我,如果這件事情傻..
發佈您的查詢結果和您的預期結果。 –
您的第一個查詢會爲通過計數不同的ID。你的第二個查詢不是。它只是獲得每個功能的PASS記錄計數 – ughai
計數之後的總和(獨特的id),是不是隻考慮了不同的ID? – RAHUL