`

分页SQL

阅读更多
MySQL:
$limit = $page* $pagesize.",".$pagesize;
select *
  from (select t1.*, t2.intro, t3.ul_size, t3.ul_name, t4.user_name
          from work as t1
          left join work_extra as t2 on t1.wid = t2.wid
          join uploads as t3 on t1.wid = t3.ulid
          join member as t4 on t1.uid = t4.uid
         where t3.ul_type = '3'
           and t1.status = '1') t
where wid in (1, 2, 3)
order by enjoyed desc limit 0, 6

Oracle:
//当前页起始游标
$startPoin = ($page-1)*$pagesize+1;
//当前页结束游戏标
$endPoin = $page*$pagesize;
select *
  from (select row_number() over(order by a.Sub_Time desc) row_num,
               a.action_id,
               d.circle_id,
               d.circle_image,
               a.title,
               to_char(a.start_time, 'yyyy-mm-dd') as start_time,
               to_char(a.end_time, 'yyyy-mm-dd') as end_time,
               a.view_count,
               a.sub_time,
               nvl(b.messagenum, 0) as messagenum,
               nvl(c.joinnum, 0) as joinnum
          from Action_Info a,
               (select Action_ID, count(User_ID) as messagenum
                  from Action_Feedback
                 group by Action_ID) b,
               (select Action_ID, count(User_ID) as joinnum
                  from Action_Join
                 group by Action_ID) c,
               Circle_Info d
         where a.Action_ID = b.Action_ID(+)
           and a.Action_ID = c.Action_ID(+)
           and a.circle_id = d.circle_id(+)
           and a.User_ID = '$userID')
Where row_num between $startPoin And $endPoin
[img][/img]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics