工資表t_salary以下:函數
id | month | name | salary |
1 | 201601 | Jim | 12 |
2 | 201601 | Bruce | 30 |
3 | 201601 | Peter | 23 |
1 | 201602 | Jim | 20 |
示例一:spa
select id,sum(salary) from t_salary group by id;
示例一是對的code
示例二:blog
select id,name,sum(salary) from t_salary group by id;
示例一會報錯。ci
由於使用group by 時,select 涉及的列要麼是分組的依據(本例:id),要麼包含在聚合函數(本例:salary)中。table