当前位置:网站首页>MySQL学习03
MySQL学习03
2022-07-03 01:29:00 【88岁带伤编程】
排序和分页操作
1.排序
数据库中查询默认的顺序为数据添加的顺序
使用order by 对查询到的数据进行排序操作
排序前:
升序排序(ASC):
order by 想以什么进行排序
SELECT * FROM list
ORDER BY salary;
降序排序(DESC):
order by 想以什么进行排序 DESC
SELECT * FROM list
ORDER BY salary DESC;

注意:
1.列的别名只能在ORDER BY 中使用,不能在WHERE中使用,否则会报错。
2.查询时WHERE应与FROM在一起,后使用ORDER BY,即先选择后排序。
2.分页操作
为什么需要分页操作?


以上是某网站的分页。
如何进行分页操作呢?
mysql使用 limit 来对数据进行分页显示。
使用方法:limit 偏移起点,偏移量;
需求一:每页显示二十条记录,此时显示第一页
需求二:每页显示二十条记录,此时显示第二页
总结:
拓展:
多表查询



通过一个表的内容找到与之关联的表再找到自己想要的数据,如下图
箭头指向。
单个选中执行,查询时间慢,效率不高,要多次网络交互信息。如下图:
如何进行多表查询?
默认两张表的数据进行笛卡尔乘积,每个数据都会与另一张表的数据逐个配对。
错误原因:缺少了多表的连接条件。
正确的实现方式

需要有连接条件。
等值连接与自连接
多表查询的分类:
非等值连接:简单来说就是一个范围,不知道具体的数据
自连接就是自己表内的数据连接
非自连接顾名思义就是与别的表的数据连接
SQL92与99语法实现内连接与外连接
内连接与外连接:
左外连接:两个表在连接过程中除了返回满足条件的行以外还返回左表中不满足条件的行。
右外连接:两个表在连接过程中除了返回满足条件的行以外还返回右表中不满足条件的行。
MySQL不支持SQL92语法中的外连接写法:
SQL99语法
采用join…on来实现内连接

左外连接:LEFT OUTER JOIN…ON
右外连接:RIGHT OUTER JOIN…ON
满外连接:MYSQL不支持满外连接,语法:FULL OUTER JOIN…ON。
边栏推荐
- Asian Games countdown! AI target detection helps host the Asian Games!
- Take you ten days to easily complete the go micro service series (II)
- Network security - vulnerabilities and Trojans
- STM32 - vibration sensor control relay on
- Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
- 7-25 read numbers (loop switch)
- Network security - cracking system passwords
- [error record] navigator operation requested with a context that does not include a naviga
- word插入公式/endnote
- His experience in choosing a startup company or a big Internet company may give you some inspiration
猜你喜欢

What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it

In the face of difficult SQL requirements, HQL is not afraid
![[Appendix 6 Application of reflection] Application of reflection: dynamic agent](/img/e7/0ee42902b178b13e9a41385267e7b6.jpg)
[Appendix 6 Application of reflection] Application of reflection: dynamic agent

STM32 - GPIO input / output mode

Take you ten days to easily complete the go micro service series (II)

Huakaiyun (Zhiyin) | virtual host: what is a virtual host

【数据挖掘】任务2:医学数据库MIMIC-III数据处理

Custom components, using NPM packages, global data sharing, subcontracting

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr

网络安全-漏洞与木马
随机推荐
Types of map key and object key
疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
网络安全-openvas
C language course information management system
Network security - talking about security threats
Performance test | script template sorting, tool sorting and result analysis
2022-02-15 reading the meta module inspiration of the influxdb cluster
VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
Everything文件搜索工具
PS去除水印详解
【Camera专题】OTP数据如何保存在自定义节点中
【Camera专题】手把手撸一份驱动 到 点亮Camera
mysql
Wordinsert formula /endnote
网络安全-NAT网络地址转换
Introduction to flask tutorial
Certaines fonctionnalités du développement d'applets
【Camera专题】Camera dtsi 完全解析
【数据挖掘】任务3:决策树分类
网络安全-密码破解