我试图改进以前写的查询。这是查询 -这些查询有什么不同?
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