其他分享
首页 > 其他分享> > 分页和排序

分页和排序

作者:互联网

排序

asc 升序 desc 降序

-- ======= 排序 =========
-- asc 升序  desc 降序
-- orde by 通过哪个字段排序,怎么排
select s.studentno,studentname,subjectname,studentresult
from student s
INNER JOIN result r
on s.studentno=r.studentno
INNER join subject sub
on sub.subjectno=r.subjectno
order by `studentresult` asc

分页

-- ========= 分页 ==========
-- 为啥分页, 缓解数据库压力,给人的体验更好
-- 语法, limit 起始值,页面大小
-- 网页应用,总的页数,页面大小
select s.studentno,studentname,subjectname,studentresult
from student s
INNER JOIN result r
on s.studentno=r.studentno
INNER join subject sub
on sub.subjectno=r.subjectno
order by `studentresult` desc
limit 1,2


子查询

-- 方式二 使用子查询
select `studentno`, `subjectno`, `studentresult` from `result`
where subjectno=(
select subjectno from `subject`
where subjectname ='数据库结构-1'
)
--  在这个基础上增加一个科目,高等数学-2 , 使用子查询
select  s.`studentno`,`studentname` from student s
INNER JOIN result r
on r.studentno=s.studentno
where `studentresult` >= 80  and `subjectno`=(
select subjectno from `subject` where `subjectname`='高等数学-2 '
)

标签:分页,--,studentno,studentresult,subjectno,INNER,排序,select
来源: https://www.cnblogs.com/ahhh7931/p/16192204.html