与工作台的LEFT JOIN错误

时间:2016-07-25 10:47:21

标签: mysql database mysql-workbench

我正在尝试获取包含总数和通过案例的案例列表。这是我写的查询 -

select totalcases.feature,passedcases.passed,totalcases.total 

from ((select feature, count(distinct templateid) as Total 
       from results 
       where build = 'random' group by feature
       ) AS totalcases) 
LEFT JOIN ((select feature,count(distinct templateid) as PASSED 
            from results 
            where build='random' and result='PASS' group by feature
       ) AS passedcases) using feature;

mysql说有一些语法错误。另外,工作台是否不允许查询在终端等不同的行中被破坏?

1 个答案:

答案 0 :(得分:1)

使用group by

可能会更简单
select  feature,
            sum(case when result = 'PASS' then  1 else 0 end) as passed,
            count(*) as totalcases 
from        results
where       build = 'random'
group       by feature
order       by feature