即时尝试获取最多行显示在表中,当我在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;
答案 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
;