2016-09-10 63 views
1

我嘗試導入SQL文件MySQL數據庫,但我遇到一個問題:WITH ROLLUP的不正確使用和DISTINCT

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 ; 

回答

2

你並不需要在GROUP BY查詢中使用DISTINCT City,因爲,因爲每個記錄結果集將已經不同。改爲使用此查詢:

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

多數民衆贊成在我的想法,但我不知道。謝謝。 – Tomasz