当前位置:网站首页>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。
边栏推荐
- 网络安全-浅谈安全威胁
- In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
- Network security - firewall
- Button button adaptive size of wechat applet
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- 网络安全-扫描
- Huakaiyun (Zhiyin) | virtual host: what is a virtual host
- Types of map key and object key
- [data mining] task 4:20newsgroups clustering
- 网络安全-防火墙
猜你喜欢
【Camera专题】手把手撸一份驱动 到 点亮Camera
STM32 - switch of relay control lamp
[leetcode] 797 and 1189 (basis of graph theory)
"Jetpack - livedata parsing"
Installation and use of serial port packet capturing / cutting tool
PS remove watermark details
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)
[camera topic] turn a drive to light up the camera
Leetcode skimming questions_ Sum of two numbers II - enter an ordered array
全链路数字化转型下,零售企业如何打开第二增长曲线
随机推荐
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
小程序开发黑马购物商城中遇到的问题
¢ growth path and experience sharing of getting an offer
网络安全-病毒
[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)
Installation and use of serial port packet capturing / cutting tool
Internal connection query and external connection
网络安全-木马
【数据挖掘】任务6:DBSCAN聚类
PS去除水印详解
mysql
Telecom Customer Churn Prediction challenge
STM32 - GPIO input / output mode
Wordinsert formula /endnote
技术大佬准备就绪,话题C位由你决定
网络安全-钓鱼
Introduction to flask tutorial
Modify table structure
Where is the future of test engineers? Confused to see
[QT] encapsulation of custom controls