我尝试将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 ;
答案 0 :(得分:3)
您不需要在DISTINCT City
查询中使用GROUP BY
,因为结果集中的每条记录都已经不同了。请改用此查询:
SELECT City
SUM(Salary) Salary_By_City
FROM employees
GROUP BY City WITH ROLLUP