WITH ROLLUP 和 DISTINCT 的错误使用

Incorrect usage of WITH ROLLUP and DISTINCT

我尝试将 sql 文件导入 MySql 数据库,但我 运行 遇到了问题:

ERROR 1221 (HY000) at line 4598: Incorrect usage of WITH ROLLUP and DISTINCT

DROP PROCEDURE IF EXISTS `sp_employees_rollup`$$
CREATE PROCEDURE `sp_employees_rollup` ()
BEGIN
SELECT Distinct City ,Sum(Salary) Salary_By_City FROM employees
GROUP BY City WITH ROLLUP;

END $$

DELIMITER ;

您不需要在 GROUP BY 查询中使用 DISTINCT City,因为结果集中的每条记录已经不同。请改用此查询:

SELECT City,
       SUM(Salary) Salary_By_City
FROM employees
GROUP BY City WITH ROLLUP