Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将count(*)与rownum一起使用_Sql_Oracle - Fatal编程技术网

Sql 将count(*)与rownum一起使用

Sql 将count(*)与rownum一起使用,sql,oracle,Sql,Oracle,我想计算客户请求和订单的时间,只显示前10个输出。我使用count和rownum函数,如下所示,但代码中没有实现顺序计数。请参阅下面我的代码,我将感谢任何建议来解决这个问题。多谢各位 SET SERVEROUT ON create or replace procedure total is begin for a in (select customer_no, count(*) as total from orders where rownum <= 10 group by custom

我想计算客户请求和订单的时间,只显示前10个输出。我使用count和rownum函数,如下所示,但代码中没有实现顺序计数。请参阅下面我的代码,我将感谢任何建议来解决这个问题。多谢各位

SET SERVEROUT ON
create or replace procedure total is
begin
for a in (select customer_no, count(*) as total from orders where rownum <= 
10 group by customer_no)
loop
dbms_output.put_line('customer number '||a.customer_no|| ' total orders 
'||a.total);

end loop;
end;
/
execute total;
drop procedure total;
不带rownum的输出示例:


你只想要10行,而不关心哪10行或它们的顺序

SELECT *
FROM (SELECT customer_no, count(*) AS total
      FROM orders
      GROUP BY customer_no)
WHERE rownum <= 10;

据报道,Oracle 12支持FETCH FIRST语法来返回给定数量的行,但我没有任何方法来测试

您能给出示例输入和预期输出吗?您尝试过使用LIMIT 10吗?我认为罗纳姆在小组赛中打得不好BY@shrek我添加输出示例。谢谢你的帮助help@arth我正在使用sql developer,它没有将限制识别为内置函数。如果你认为我可以使用,你能提供一个有限制的例子吗。谢谢,我不明白。首先,要求是什么?计算每个客户的数量,然后列出数量最多的十个客户?如果是这样的话,你的尝试不会有任何效果。那么,你为什么要使用程序呢?这是一个简单的SQL语句。对我来说很好。我也没有甲骨文12。非常感谢。
Procedure TOTAL compiled

customer number 1098 total orders 25
customer number 1041 total orders 11
customer number 1000 total orders 18
customer number 1003 total orders 16



PL/SQL procedure successfully completed.


Procedure TOTAL dropped.
SELECT *
FROM (SELECT customer_no, count(*) AS total
      FROM orders
      GROUP BY customer_no)
WHERE rownum <= 10;