自学MYSQL-学完分组函数和分组查询部分-20200407

# 分组查询

/*

语法:

SELECT 分组函数,列(要求出现在group by的后面)、

FROM 表名

WHERE 筛选条件

GROUP BY 分组的列表

ORDER BY 子句

*/

SELECT AVG(salary), department_id

FROM employees

GROUP BY department_id;

SELECT max(salary), job_id

FROM employees

GROUP BY job_id

ORDER BY max(salary);

SELECT COUNT(*),location_id

FROM departments

GROUP BY location_id;

SELECT AVG(salary),email,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;

-- 62

你可能感兴趣的:(自学MYSQL-学完分组函数和分组查询部分-20200407)