码迷,mamicode.com
首页 > 数据库 > 详细

一条带分页的sql

时间:2016-10-11 18:24:31      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/zhaoblog/p/5950264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!