rownum不工作sql

时间:2015-05-21 22:59:07

标签: sql oracle rownum

即时尝试获取最多行显示在表中,当我在rownum中使用时我得到错误:“SQL命令未正确结束”,还有其他我可以做的事情?

 select src_customer ,count(sending.src_customer) as bla
    from sending
    group by sending.src_customer
    order by bla desc
    where rownum=1; 

2 个答案:

答案 0 :(得分:2)

据推测,你想要最大的一行。在Oracle 12中,您可以使用ANSI标准FETCH子句:

select src_customer, count(s.src_customer) as bla
from sending s
group by s.src_customer
order by bla desc
fetch first 1 row only;

在早期版本中,您需要一个子查询:

select *
from (select src_customer, count(s.src_customer) as bla
      from sending s
      group by s.src_customer
      order by bla desc
     ) s
where rownum = 1; 

答案 1 :(得分:1)

您的WHERE子句应该在FROM子句之后。

请参阅Oracle documentation for more details

因此,您的查询应该像

select src_customer ,count(sending.src_customer) as bla
    from sending
    where rownum=1
    group by sending.src_customer
    order by bla desc
    ;