Oracle.Query中MySQL Limit的等价物包括几个表?

发布于 2024-11-14 23:41:12 字数 677 浏览 2 评论 0原文

我在 MySQL 中有以下查询,希望将其转换为 Oracle。我尝试了Oracle中的row_number()函数和子查询,但无法使其正常运行。该查询有点奇怪并且涵盖多个表。

原始 MySQL 查询:

select DISTINCT uc.virtual_clip_id, uc.clip_id, uc.duration, uc.title,  
                uc.thumbnail,uc.filename, uc.description, uc.block_id_start, 
                uc.block_id_end, u.uname,uc.cdate, uc.ctime, uc.privacy_level, uc.user_id 
FROM
    user_clips uc, users u, user_like ul

WHERE 
     ul.user_id="+user_id+" and u.user_id=uc.user_id and  
     uc.virtual_clip_id=ul.virtual_clip_id and ul.like_status='1'
ORDER by 
      virtual_clip_id DESC
LIMIT "+offset+",4"

我找不到替换 LIMIT 的正确语句,因此使查询针对 Oracle 运行。

谢谢。

I have the following query in MySQL and want to convert it to Oracle. I tried row_number() function and subqueries in Oracle but could not make it run properly. The query is kinda weird and covers multiple tables.

Original MySQL Query:

select DISTINCT uc.virtual_clip_id, uc.clip_id, uc.duration, uc.title,  
                uc.thumbnail,uc.filename, uc.description, uc.block_id_start, 
                uc.block_id_end, u.uname,uc.cdate, uc.ctime, uc.privacy_level, uc.user_id 
FROM
    user_clips uc, users u, user_like ul

WHERE 
     ul.user_id="+user_id+" and u.user_id=uc.user_id and  
     uc.virtual_clip_id=ul.virtual_clip_id and ul.like_status='1'
ORDER by 
      virtual_clip_id DESC
LIMIT "+offset+",4"

I could not find the proper statement to replace LIMIT so make the query run against Oracle.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So要识趣 2024-11-21 23:41:12

这有点痛苦,但你可以使用 rownum

select * from
(
select rownum as row_number, base_data.* from
(
select DISTINCT uc.virtual_clip_id, uc.clip_id, uc.duration, uc.title,
 uc.thumbnail,uc.filename, uc.description, uc.block_id_start, uc.block_id_end, u.uname,uc.cdate, uc.ctime, uc.privacy_level, uc.user_id FROM user_clips uc, users u, user_like ul

WHERE ul.user_id="+user_id+" and u.user_id=uc.user_id and
 uc.virtual_clip_id=ul.virtual_clip_id and ul.like_status='1' 
) base_data
ORDER by virtual_clip_id DESC
) sorted
WHERE row_number <= X

我子选择两次的唯一原因是不同的是执行一个组,并且我将排序保留在它之外,它可以通过单个子选择来完成。

It's a bit of a pain but you can use rownum

select * from
(
select rownum as row_number, base_data.* from
(
select DISTINCT uc.virtual_clip_id, uc.clip_id, uc.duration, uc.title,
 uc.thumbnail,uc.filename, uc.description, uc.block_id_start, uc.block_id_end, u.uname,uc.cdate, uc.ctime, uc.privacy_level, uc.user_id FROM user_clips uc, users u, user_like ul

WHERE ul.user_id="+user_id+" and u.user_id=uc.user_id and
 uc.virtual_clip_id=ul.virtual_clip_id and ul.like_status='1' 
) base_data
ORDER by virtual_clip_id DESC
) sorted
WHERE row_number <= X

The only reason I subselected twice was the distinct is performing a group and I kept the ordering outside of it, it could be done with a single subselect.

走过海棠暮 2024-11-21 23:41:12
select * from (
select DISTINCT
    uc.virtual_clip_id
  , uc.clip_id
  , uc.duration
  , uc.title
  , uc.thumbnail
  , uc.filename
  , uc.description
  , uc.block_id_start
  , uc.block_id_end
  , u.uname
  , uc.cdate
  , uc.ctime
  , uc.privacy_level
  , uc.user_id
  , row_number() over(order by uc.virtual_clip_id DESC) row_nr
   FROM
    user_clips uc
  , users u
  , user_like ul
  WHERE
    ul.user_id         = "+user_id+"
and u.user_id          = uc.user_id
and uc.virtual_clip_id = ul.virtual_clip_id
and ul.like_status     = '1'
)
 where row_nr < 5 ;
select * from (
select DISTINCT
    uc.virtual_clip_id
  , uc.clip_id
  , uc.duration
  , uc.title
  , uc.thumbnail
  , uc.filename
  , uc.description
  , uc.block_id_start
  , uc.block_id_end
  , u.uname
  , uc.cdate
  , uc.ctime
  , uc.privacy_level
  , uc.user_id
  , row_number() over(order by uc.virtual_clip_id DESC) row_nr
   FROM
    user_clips uc
  , users u
  , user_like ul
  WHERE
    ul.user_id         = "+user_id+"
and u.user_id          = uc.user_id
and uc.virtual_clip_id = ul.virtual_clip_id
and ul.like_status     = '1'
)
 where row_nr < 5 ;
┾廆蒐ゝ 2024-11-21 23:41:12
select * 
from 
 (
  select DISTINCT uc.virtual_clip_id, uc.clip_id, uc.duration, uc.title,  
                  uc.thumbnail,uc.filename, uc.description, uc.block_id_start, 
                  uc.block_id_end, u.uname,uc.cdate, uc.ctime, uc.privacy_level, uc.user_id 
                , row_number() over(order by uc.virtual_clip_id desc) rn
  FROM
      user_clips uc, users u, user_like ul
  WHERE 
       ul.user_id="+user_id+" and u.user_id=uc.user_id and  
       uc.virtual_clip_id=ul.virtual_clip_id and ul.like_status='1'
 )
where rn between "+offset+" and 4
select * 
from 
 (
  select DISTINCT uc.virtual_clip_id, uc.clip_id, uc.duration, uc.title,  
                  uc.thumbnail,uc.filename, uc.description, uc.block_id_start, 
                  uc.block_id_end, u.uname,uc.cdate, uc.ctime, uc.privacy_level, uc.user_id 
                , row_number() over(order by uc.virtual_clip_id desc) rn
  FROM
      user_clips uc, users u, user_like ul
  WHERE 
       ul.user_id="+user_id+" and u.user_id=uc.user_id and  
       uc.virtual_clip_id=ul.virtual_clip_id and ul.like_status='1'
 )
where rn between "+offset+" and 4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文