语法:
select 分组函数,列(要求出现在group by的后面)
from 表
where ..
group by 分组的列表
order by ...
#案例:查询各个部门的平均工资
SELECT AVG(salary),department_id
FROM employees
GROUP BY
department_id
ORDER BY
department_id DESC;
#案例:查询每个工种的最高工资
SELECT
MAX(salary),job_id
FROM
employees
GROUP BY
job_id;
#案例:查询每个部门的位置个数
SELECT
COUNT(location_id),department_name
FROM
departments
GROUP BY
department_name;
#案例:查询邮箱中包含a字符的,每个部门的平均工资
SELECT
AVG(salary),department_id
FROM
employees
WHERE
email LIKE('%a%')
GROUP BY
department_id;
#案例:查询有奖金的每个领导手下员工的最高工资
SELECT
MAX(salary),manager_id
FROM
employees
WHERE
commission_pct IS NOT NULL
GROUP BY
manager_id;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。