当前位置:网站首页>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。
边栏推荐
猜你喜欢

Vant 实现简单的登录注册模块以及个人用户中心

The testing process that software testers should know

STM32 - Application of external interrupt induction lamp

Some functions of applet development

In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?

Processing of tree structure data

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

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
![[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array](/img/2a/98400b0d0b5eda1e52abae30746f2b.jpg)
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array

A simple tool for analyzing fgui dependencies
随机推荐
[camera topic] complete analysis of camera dtsi
Technology sharing | Frida's powerful ability to realize hook functions
Network security - password cracking
小程序开发黑马购物商城中遇到的问题
疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
String splicing function of MySQL
C application interface development foundation - form control (1) - form form
云原生题目整理(待更新)
Telecom Customer Churn Prediction challenge
Analyzing several common string library functions in C language
Cloud native topic sorting (to be updated)
Certaines fonctionnalités du développement d'applets
Types of map key and object key
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
[data mining] task 3: decision tree classification
How is the mask effect achieved in the LPL ban/pick selection stage?
Modify table structure
Processing of tree structure data
High resolution network (Part 1): Principle Analysis
Everything file search tool