SQL 服务器排序依据与子查询中的最大行数
SQL Server order by with max rows in subquery
以下查询适用于 PostgreSQL,我想知道为什么它不适用于 SQL Server 2016。
select * from (values (1),(2)) as a(a)
UNION
(
select * from (values (1),(2)) as a(a)
order by 1 desc
offset 0 rows fetch first 1 rows only
)
order by 1 desc offset 0 rows fetch first 1 rows only
谁能给我解释一下为什么这里不支持 order by?
有趣的是,下面的另一种表达方式非常有效
select * from (values (1),(2)) as a(a)
where a.a in(
select * from (values (1),(2)) as a(a)
order by 1 desc
offset 0 rows fetch first 1 rows only
)
order by 1 desc offset 0 rows fetch first 1 rows only
这是一个错误吗?
联合后的查询需要呈现为select,像这样:
select * from (values (1),(2)) as a(a)
UNION
select * from
(
select * from (values (1),(2)) as a(a)
order by 1 desc
offset 0 rows fetch first 1 rows only
) b
order by 1 desc offset 0 rows fetch first 1 rows only
以下查询适用于 PostgreSQL,我想知道为什么它不适用于 SQL Server 2016。
select * from (values (1),(2)) as a(a)
UNION
(
select * from (values (1),(2)) as a(a)
order by 1 desc
offset 0 rows fetch first 1 rows only
)
order by 1 desc offset 0 rows fetch first 1 rows only
谁能给我解释一下为什么这里不支持 order by?
有趣的是,下面的另一种表达方式非常有效
select * from (values (1),(2)) as a(a)
where a.a in(
select * from (values (1),(2)) as a(a)
order by 1 desc
offset 0 rows fetch first 1 rows only
)
order by 1 desc offset 0 rows fetch first 1 rows only
这是一个错误吗?
联合后的查询需要呈现为select,像这样:
select * from (values (1),(2)) as a(a)
UNION
select * from
(
select * from (values (1),(2)) as a(a)
order by 1 desc
offset 0 rows fetch first 1 rows only
) b
order by 1 desc offset 0 rows fetch first 1 rows only