語(yǔ)法:
select 分組函數(shù),列(要求出現(xiàn)在group by的后面)
from 表
where ..
group by 分組的列表
order by ...
目前創(chuàng)新互聯(lián)建站已為上千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、夏津網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
#案例:查詢各個(gè)部門的平均工資
SELECT AVG(salary),department_id
FROM employees
GROUP BY
department_id
ORDER BY
department_id DESC;
#案例:查詢每個(gè)工種的最高工資
SELECT
MAX(salary),job_id
FROM
employees
GROUP BY
job_id;
#案例:查詢每個(gè)部門的位置個(gè)數(shù)
SELECT
COUNT(location_id),department_name
FROM
departments
GROUP BY
department_name;
#案例:查詢郵箱中包含a字符的,每個(gè)部門的平均工資
SELECT
AVG(salary),department_id
FROM
employees
WHERE
email LIKE('%a%')
GROUP BY
department_id;
#案例:查詢有獎(jiǎng)金的每個(gè)領(lǐng)導(dǎo)手下員工的最高工資
SELECT
MAX(salary),manager_id
FROM
employees
WHERE
commission_pct IS NOT NULL
GROUP BY
manager_id;