我有以下疑问。我想从 SUM 中减去数字,然后只返回结果不是 0 的数字。任何帮助将不胜感激。我也很想看看这是否可以在一个查询中完成。我用 HAVING 子句尝试了它,但它返回了错误的结果。使用 SQL Server 2008
SELECT
(
SELECT station_id, SUM(tcl_missing + tcl_not_missing) as tcl_total
FROM tcl_missing_summary
GROUP BY station_id
) as a
(
SELECT station_id, SUM(total) as total
FROM tcl_breakdown_op
WHERE tr_standard not like '%cru'
GROUP BY station_id
) as b
WHERE a.tcl_total - total <> 0