无法对包含聚合或子查询的表达式执行聚合功能。 SQL Server 2012

时间:2018-12-11 10:54:54

标签: sql sql-server tsql

SELECT SUM((qty * (SELECT gross_wt
                   FROM lpr_productmaster
                   WHERE productid = lpr_order_detail.productid))) AS prodwt
FROM lpr_order_detail
WHERE order_id = 413
GROUP BY order_id;

1 个答案:

答案 0 :(得分:2)

尝试一下:

SELECT SUM(qty * gross_wt) AS prodwt
FROM lpr_order_detail 
INNER JOIN lpr_productmaster
    ON lpr_order_detail.productid = lpr_productmaster.productid
WHERE order_id = 413
GROUP BY order_id;

想法是重写查询,以免使用子查询。