2012-05-21 82 views
0

我想要做一個sql查詢,它將採用兩個視圖並比較數據中的差異並僅顯示非零的數據。到目前爲止,我有以下,但它出現一個錯誤,說「子查詢返回多個值。」使用您正在使用哪個`RDBMS` SQL Server 2008中如何比較兩個表並只顯示結果不等於0

select * from stl_wk_vw where 
ABS((select sum(missing+non_missing) as total from tdn_summary as b join stl_wk_vw as a on a.id = b.id group by b.id) 
- 
(select sum(st_total) from stl_wk_vw as a join tdn_summary as b on a.id = b.id where standard not like '%non' group by b.id)) > 0 
+0

? – Quassnoi

+0

你如何比較st1_wk_vw。*和sum(st_total)?請問st1_wk_vw只有一列嗎? –

回答

0
SELECT * 
FROM stl_wk_vw a 
JOIN tdn_summary b 
ON  b.id = a.id 
GROUP BY 
     b.id 
HAVING ABS(SUM(missing + non_missing)) > SUM(CASE WHEN standard NOT LIKE '%non' THEN st_total END) 
相關問題