1
SELECT 
    count(A.gross_c) AS cnt, 
    SUM(A.gross_c) AS Gross_c, 
    B.store_name
FROM hr_location_c_verified A 
JOIN hr_stores B ON A.c_location = B.id
WHERE A.c_ref_fkid IS NULL
GROUP BY A.c_location

我正在执行此查询,输出结果正确,但计数显示错误。

请帮我。

4

1 回答 1

2

这可能是因为您的JOIN产生了更多行。

一种方法是使用DISTINCT关键字。

SELECT 
    count(DISTINCT A.gross_c) AS cnt, 
    SUM(A.gross_c) AS Gross_c, 
    B.store_name FROM hr_location_c_verified A 
JOIN hr_stores B ON A.c_location = B.id
WHERE A.c_ref_fkid IS NULL
GROUP BY A.c_location
于 2013-03-07T12:17:29.847 回答