单表查询总结
语句顺序
SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ...
执行顺序
FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY
FROM从某张表中查询数据,
先经过WHERE条件筛选数据,
对这些有价值的数据进行分组GROUP BY,
分组之后可以使用HAVING进一步筛选,
SELECT查询出来最终结果,
最后ORDER BY排序输出结果。
综合例题:找出除MANAGER岗位之外的每个岗位的平均薪资,要求显示平均薪资大于1500的,,要求按照平均薪资降序排列。
SELECT
job, AVG(sal) AS avg_sal
FROM
emp
WHERE
job != 'manager'
GROUP BY
job
HAVING
AVG(sal) > 1500
ORDER BY
avg_sal DESC;
标签:...,GROUP,MySQL7,sal,查询,单表,WHERE,ORDER,SELECT
From: https://www.cnblogs.com/Ashen-/p/17032227.html