我正在做 sql 查询,它用于从数据库中检索记录以显示在报告中。问题是当我将计算作为子查询放置时,SENOKO列在每一行中都显示有冗余记录。我已经通过将其作为主要查询进行了测试,报告中显示的数字是正确的。
DO 作为子查询
SELECT whbal.customer, customer.imp_license_no,
(SELECT SUM(CONVERT(DECIMAL(8, 3), (CONVERT(DECIMAL(8, 3), whbal.qty_good) +
CONVERT(DECIMAL(8, 3), whbal.qty_slack)) *
CONVERT(DECIMAL(8, 3), whbal.std_weight) / 1000))
FROM whbal
INNER JOIN customer ON whbal.customer = customer.customer
WHERE whbal.warehouse = 'SKW') AS SENOKO
FROM customer
INNER JOIN whbal ON whbal.customer = customer.customer
WHERE (whbal.customer BETWEEN @cust1 AND @cust2)
GROUP BY whbal.customer, customer.imp_license_no
DO 作为主要查询
SELECT whbal.customer,
customer.psq_level,
SUM(CONVERT(DECIMAL(8, 3), (CONVERT(DECIMAL(8, 3), whbal.qty_good) +
CONVERT(DECIMAL(8, 3), whbal.qty_slack)) *
CONVERT(DECIMAL(8, 3), whbal.std_weight) / 1000)) AS SENOKO
FROM whbal
INNER JOIN customer ON whbal.customer = customer.customer
WHERE (whbal.customer BETWEEN @cust1 AND @cust2) AND (whbal.warehouse = 'SKW')
GROUP BY whbal.customer, customer.psq_level
有人知道我的查询有什么问题吗?请帮助和指导提前谢谢