0

我想做一个 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
4

1 回答 1

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)
于 2012-05-21T19:07:52.563 回答