当我在where子句中使用别名引用时,为什么我得到一个"Invalid column name“错误消息207 Level 16 State 1 Line 14?创建表temp ( col1 nvarchar(25),col2 nvarchar(25) )
insert into temp
values ('Babahoyo', 'Ecuador'),
('Stavanger', 'Norway'),
('Seattle', 'USA'),
('New York City', 'USA')
select
row_number() over (order by col2) as N,
col1, col2
from
temp
where
n = 2
发布于 2020-11-13 01:12:28
您不能将an alias reference
放在where clause
中
select * from
(
select row_number() OVER (ORDER BY col2) as N, col1, col2
from temp
)A
where n = 2
发布于 2020-11-13 01:13:23
使用offset
/fetch
select t.*
from temp
order by col2
offset 1 row fetch 1 row only
https://stackoverflow.com/questions/64808535
复制相似问题