Mysql子查询

时间:2017-01-23 21:29:32

标签: mysql

我试图一起运行时有2个查询。我似乎可以让它工作。每个查询由他们自己工作。但是一旦我尝试将它们与子查询一起添加,我似乎无法开始工作

SELECT T1,100 * SUM(IF(C1='UNKNOWN', 0, 1)) / COUNT(C1) as 'MATCHING' FROM t1.CSLog WHERE CSHOUSE LIKE 'N%' group by CSHOUSE


SELECT T1,100 * SUM(IF(C1='UNKNOWN', 1, 0)) / COUNT(C1) as 'NOTMATCHING' FROM t1.CSLog WHERE CSHOUSE LIKE 'N%' group by CSHOUSE

输出应该如下所示

t1 | MATCHING  | NOTMATCHING

2  | 100%      |    0.0%
3  | 0.0       |   100%

1 个答案:

答案 0 :(得分:1)

这个选择怎么样?

SELECT 
  T1,
  100 * SUM(IF(C1='UNKNOWN', 0, 1)) / COUNT(C1) as 'MATCHING',
  100 * SUM(IF(C1='UNKNOWN', 1, 0)) / COUNT(C1) as 'NOTMATCHING'
FROM t1.CSLog 
WHERE CSHOUSE LIKE 'N%' 
group by CSHOUSE