gpt4 book ai didi

c# - PostgreSQL 中的 ROW_NUMBER 查询?

转载 作者:行者123 更新时间:2023-11-29 12:08:08 26 4
gpt4 key购买 nike

--1
(select * , row_number() over (order by columnname) as tempcolumn
from tablename )

--2
select * , row_number() over (order by defid) as tempcolumn
from fields
where tempcolumn between 1 and 2

第一个查询将给整个表添加一个新列。

我需要在检查临时列的范围后显示结果。 我尝试的第二个查询抛出一个错误,如 tempcolumn doesnot exist

最佳答案

你可以使用子查询:

SELECT * FROM (
select *,ROW_NUMBER() OVER(ORDER BY columnname) as tempcolumn
from tablename) sub
WHERE tempcolumn <= 2;

您不能在同一级别的 WHERE 子句中使用 SELECT 的别名,也不能将 ROW_NUMBER() 作为 的一部分使用哪里

更多信息:

关于c# - PostgreSQL 中的 ROW_NUMBER 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50718824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com