189 8069 5689

mysql筛选后分组查询

语法:
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;

当前标题:mysql筛选后分组查询
新闻来源:http://jkwzsj.com/article/iehdds.html

其他资讯