当前位置:网站首页>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。
边栏推荐
猜你喜欢
Main features of transport layer TCP and TCP connection
Asian Games countdown! AI target detection helps host the Asian Games!
Introduction to kotlin collaboration
【Camera专题】Camera dtsi 完全解析
Processing of tree structure data
Installation and use of serial port packet capturing / cutting tool
【数据挖掘】任务2:医学数据库MIMIC-III数据处理
自定义组件、使用npm包、全局数据共享、分包
[data mining] task 4:20newsgroups clustering
Performance test | script template sorting, tool sorting and result analysis
随机推荐
Network security ACL access control list
STM32 - GPIO input / output mode
Technology sharing | Frida's powerful ability to realize hook functions
Cloud native topic sorting (to be updated)
网络安全-信息收集
云原生题目整理(待更新)
2022 spring "golden three silver four" job hopping prerequisites: Software Test interview questions (with answers)
Wordinsert formula /endnote
Button button adaptive size of wechat applet
Network security - vulnerabilities and Trojans
STM32 - vibration sensor control relay on
CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
网络安全-openvas
网络安全-中间人攻击
Network security NAT network address translation
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
Function definition and call, this, strict mode, higher-order function, closure, recursion
Summary of interval knowledge
Introduction to kotlin collaboration
Processing of tree structure data