您好,登錄后才能下訂單哦!
按表達(dá)式或函數(shù)分組:
#案例:按員工的姓名的長(zhǎng)度分組,查詢每一組的員工個(gè)數(shù),篩選員工個(gè)數(shù)大于五
SELECT
COUNT(*),LENGTH(last_name)
FROM
employees
GROUP BY
LENGTH(last_name)
HAVING
COUNT(*)>5;
按多個(gè)字段分組:
#案例:查詢每個(gè)部門每個(gè)工種的員工的平均工資
SELECT
AVG(salary),department_id,job_id
FROM
employees
GROUP BY
department_id,job_id;
排序
#案例:查詢每個(gè)部門每個(gè)工種的部門編號(hào)不為null的員工的平均工資>10000,并且按平均工資的高低顯示
SELECT
AVG(salary),department_id,job_id
FROM
employees
WHERE
department_id IS NOT NULL
GROUP BY
department_id,job_id
HAVING
AVG(salary)>10000
ORDER BY
AVG(salary) DESC;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。