您好,登錄后才能下訂單哦!
語法:
select 分組函數(shù),列(要求出現(xiàn)在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;
#案例:查詢每個部門的位置個數(shù)
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;
#案例:查詢有獎金的每個領(lǐng)導(dǎo)手下員工的最高工資
SELECT
MAX(salary),manager_id
FROM
employees
WHERE
commission_pct IS NOT NULL
GROUP BY
manager_id;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。