下面的查询用于从数据库中检索记录以显示在报告中。但是 SENOKO 和 EUNOS 列在每一行中显示重复的总数。这似乎子查询未连接到主查询导致未进行过滤。
SELECT whbal.customer, customer.imp_license_no, customer.psq_level,
(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 WHERE warehouse='SKW') AS SENOKO
(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 WHERE warehouse='EKW') AS EUNOS
FROM customer
INNER JOIN whbal ON whbal.customer=customer.customer AND whbal.date_create<=@date1
INNER JOIN stktype ON whbal.stock_type=stktype.stock_type
WHERE whbal.customer BETWEEN @cust1 AND @cust2 AND whbal.stock_type=@type
GROUP BY whbal.customer, customer.customer, customer.imp_license_no, customer.psq_level
结果:
有谁知道是什么问题和解决方法,请指教和指导。提前致谢