数据库
首页 > 数据库> > MySQL分页和排序

MySQL分页和排序

作者:互联网

mysql分页和排序

排序(order by):

SELECT 字段 FROM 表 JOIN 表 ON 条件 WHERE 条件 ORDER BY 字段 DESC/ASC

SELECT student.`StudentNo`,`StudentName`,`SubjectName`,`StudentResult` FROM `student` 
RIGHT JOIN`result` ON student.`StudentNo`=result.`StudentNo` 
INNER JOIN `subject` ON result.`SubjectNo`=subject.`SubjectNo`
WHERE `SubjectName`='线性代数' 
ORDER BY `StudentResult` DESC

image

分页(limit):缓解数据库压力,增加观赏性 瀑布流:无限往下刷

语法:limit 起始位置(第几条数据,从0开始) 页面大小

SELECT student.`StudentNo`,`StudentName`,`SubjectName`,`StudentResult` FROM `student` 
RIGHT JOIN`result` ON student.`StudentNo`=result.`StudentNo` 
INNER JOIN `subject` ON result.`SubjectNo`=subject.`SubjectNo`
WHERE `SubjectName`='线性代数' 
ORDER BY `StudentResult` DESC
LIMIT 1,1

image

网页应用:

LIMIT (第N页-1)*pageSize,pageSize

标签:JOIN,分页,StudentNo,StudentResult,SubjectNo,result,student,MySQL,排序
来源: https://www.cnblogs.com/yuanyu610/p/15861234.html