一条带分页的sql

Posted xue123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一条带分页的sql相关的知识,希望对你有一定的参考价值。

SELECT *
FROM (SELECT USERID,
TYPE,
TYPE_DESC,
SEX,
USERNAME,
HEADPORTRAIT,
HOSPITAL,
HLEVEL,
DEPT,
JOBTITLE,
PRICE,
TIME,
INTRODUCE,
ISFRIEND,
ROWNUM rn
FROM (SELECT rownum R,
a.expert_id as USERID,
a.expert_id as TYPE,
b.type_desc as TYPE_DESC,
a.sex as SEX,
a.user_name as USERNAME,
a.head_portrait as HEADPORTRAIT,
h.hospital_name as HOSPITAL,
H.H_LEVEL AS HLEVEL,
c.jobtitle_name as JOBTITLE,
d.dept_name as DEPT,
e.price as PRICE,
e.time as TIME,
a.introduce as INTRODUCE,
CASE
WHEN (SELECT COUNT(*)
FROM T_GROUP_RELATION X
WHERE X.USER_ID = v_userId
AND X.FRIEND_ID = a.expert_id) > 0 THEN
1
ELSE
0
END AS ISFRIEND
from T_EXPERT_INFO a,
T_EXPERT_TYPE_INFO b,
T_JOBTITLE c,
T_HOSPITAL h,
T_DEPT d,
T_EXPERT_PRICE_INFO e
where a.expert_type = b.type_id
and a.jobtitle_id = c.jobtitle_id
and a.hospital_id = h.HOSPITAL_ID
and a.dept_id = d.dept_id
and e.expert_id = a.expert_id
ORDER BY a.create_time DESC)
WHERE ROWNUM <= page * pageSize)
WHERE rn >= ((page - 1) * pageSize) + 1;

以上是关于一条带分页的sql的主要内容,如果未能解决你的问题,请参考以下文章

java中数据库中实现分页的sql语句要求每页十条要查询的是第二页

关于mybatis物理分页的问题,求大神帮忙看看

Jsp页面,结果集分页和sql(top)分页的性能对比

请问,如何用一条SQL查询出分页的数据和总记录数啊?MySQL的!不用存储

SQL server分页的四种方法(算很全面了)

分页sql