您好,登錄后才能下訂單哦!
按表達式或函數分組:
#案例:按員工的姓名的長度分組,查詢每一組的員工個數,篩選員工個數大于五
SELECT
COUNT(*),LENGTH(last_name)
FROM
employees
GROUP BY
LENGTH(last_name)
HAVING
COUNT(*)>5;
按多個字段分組:
#案例:查詢每個部門每個工種的員工的平均工資
SELECT
AVG(salary),department_id,job_id
FROM
employees
GROUP BY
department_id,job_id;
排序
#案例:查詢每個部門每個工種的部門編號不為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;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。