MySql教程

MySQL分页和排序

本文主要是介绍MySQL分页和排序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

mysql分页和排序

排序(order by):

  • 升序 ASC
  • 降序 DESC

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

这篇关于MySQL分页和排序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!