当前位置:网站首页>【sql语句基础】——查(select)(单表查询顺序补充)
【sql语句基础】——查(select)(单表查询顺序补充)
2022-06-13 11:00:00 【InfoQ】
分组(group by)过滤(having)排序(order by)分页(limit)场景不同,顺序不同,查询结果也将不同甚至报错查询格式
select column1,column2,column3... from table
group by -- 分组
having -- 过滤
order by -- 排序
limit -- 分页
例题代码示例
平均工资最高两个部门部门号和平均工资低于1000则不显示分析:
- 平均工资:使用AVG();
- 按部门查询:GROUP BY 字段;
- 平均工资需要超过1000:HAVING 平均工资>1000;【用到了第一步和第二部的结果】
- 平均工资最高:ORDER BY 字段 DESC;【平均工资排序,用到了第三步的结果】
- 两个部门:分页LIMIT 0,2; 【取平均工资最高且大于1000的两个哥部门,需要用到第四部排序后的结果】
代码演示
SELECT AVG(sal)AS avg_sal,deptno
FROM emp --查询emp表
GROUP BY deptno --按部门号分组
HAVING avg_sal>1000 --赛选平均工资大于1000
ORDER BY avg_sal DESC --降序排列
LIMIT 0,2; --0表示从第一行开始,2表示查询两行,即查询第一行和第二行
边栏推荐
- Use of servers
- Private computing fat core concepts and stand-alone deployment
- 【20220526】UE5.0.2 release d11782b
- Go 要加个箭头语法,这下更像 PHP 了!
- Euler function and finding Euler function by linear sieve
- There is no suspense about the first one in the overtime table of the Internet company!
- Prim finding minimum spanning tree (naive dense graph)
- Advanced technology management - what management tools can managers use
- The first laravel workflow engine released the official version of v1.0
- Test cases that testers must master
猜你喜欢

状态压缩DP例题(旅行商问题和填矩形问题)

On the exploitation of a horizontal ultra vires vulnerability

终于,月入 20000 !!

Full stack development practice | integrated development of SSM framework

As a tester, these basic knowledge are essential

基于Vue+Nest.js+MySQL的跨平台开源社区运营管理系统

第七章 文件管理作业

Ue5 random point in bounding boxf from stream

Talk about MySQL indexing mechanism

Pagoda access changed from IP to domain name
随机推荐
数据库学习笔记(第十六章)
To vent their dissatisfaction with their superiors, Baidu post-95 programmers were sentenced to 9 months for deleting the database
About instruction set bits and instruction architecture bits
Ubuntu installs MySQL compressed package for future reference
2021CCPC网络赛题解加总结
宝塔添加一个网站:PHP项目
高斯消元求n元方程组
2022煤矿探放水特种作业证考试题库模拟考试平台操作
5.5 clock screensaver
Go needs to add an arrow syntax, which is more like PHP!
Count the number of special subsequences (0, 1, 2) DP
Full stack development practice | integrated development of SSM framework
CommonAPI与AUTOSAR AP通讯管理的异同
我们用了一个周末,将 370 万行代码迁移到了 TypeScript
Idea remote debugging jar submitted by spark submit
Wechat applet customer service automatic reply - PHP implementation
[dynamic planning] beginner level
Web 3.0?高成本版的P2P而已
d求值两次map
Prim求最小生成树(朴素版稠密图)