2017-01-23 211 views
-1

我有2個查詢即時嘗試運行在一起。我似乎可以得到它的工作。他們每個查詢工作自交。但一旦我嘗試使其與子查詢一起加入我似乎無法得到工作Mysql子查詢

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% 
+0

輸出沒有再次輸入:-( – Strawberry

回答

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