我做了一个查询,我想添加一个“SENOKO”列,通过使用数据库中的字段来计算总和。如果我没有按 SENOKO 分组,那么重复的结果将显示在报告中。为了避免重复记录,我想通过 SENOKO 分组,但错误显示如下:
列名“SENOKO”无效
SELECT customer.customer, customer.imp_license_no, customer.psq_level, whbal.stock_type, (SELECT SUM((CONVERT(DECIMAL(9, 3), qty_good) + CONVERT(DECIMAL(9, 3), qty_slack)) * CONVERT(DECIMAL(9, 3), std_weight) / 1000) FROM whbal WHERE warehouse='SKW')AS SENOKO
FROM customer
INNER JOIN whbal ON customer.customer=whbal.customer
INNER JOIN stktype ON whbal.stock_type=stktype.stock_type
WHERE customer.customer BETWEEN @cust1 AND @cust2 AND whbal.stock_type=@type
GROUP BY customer.customer, customer.imp_license_no, customer.psq_level, whbal.stock_type, SENOKO
有人可以帮忙吗?