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
Sql 在Postgres中使用限制1_Sql_Postgresql_Sql Limit - Fatal编程技术网

Sql 在Postgres中使用限制1

Sql 在Postgres中使用限制1,sql,postgresql,sql-limit,Sql,Postgresql,Sql Limit,我有以下sql查询,它在MYSQL上运行良好,但由于最后一个limit 1子句,在Oracle和sql Server上出现错误。我的问题是-根据PostgreSQL,这个limit 1子句有效吗?我能指望它在Postgres上成功运行吗 select customer_number from (select customer_number, count(*) from orders group by customer_number order by count(*) desc limi

我有以下sql查询,它在MYSQL上运行良好,但由于最后一个limit 1子句,在Oracle和sql Server上出现错误。我的问题是-根据PostgreSQL,这个limit 1子句有效吗?我能指望它在Postgres上成功运行吗

select customer_number 
from
(select 
customer_number,
count(*) 
from
orders
group by 
customer_number 
order by count(*) desc limit 1) a

)

对于
sql server
您需要使用
top

select top 1 customer_number,count(*) 
from orders
group by customer_number 
order by count(*) desc 

limit
受某些数据库支持,但并非所有数据库都支持。SQL标准是:

select customer_number
from orders
group by customer_number 
order by count(*) desc 
offset 1 row fetch first 1 row only;