我想做一个sql查询,它将采用两个视图并比较数据中的差异,并仅显示非零值。到目前为止,我有下面的内容,但它出现了一个错误,说“子查询返回的值超过1”。使用SQL Server 2008
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 :(得分: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)