0

我在这里有一个游标声明:

declare c cursor
for     (select ProductName, ListPrice
        from Products
        where ListPrice > 700)

但是如果我添加一个order by子句,我会得到一个错误:

declare c cursor
for     (select ProductName, ListPrice
        from Products
        where ListPrice > 700
        order by ListPrice desc)

错误:Incorrect syntax near the keyword 'order'.

但是如果我去掉括号,错误就会消失:

declare c cursor
for     select ProductName, ListPrice
        from Products
        where ListPrice > 700
        order by ListPrice desc

也许我有点不清楚括号在 SQL Server 中的作用。是什么赋予了?为什么order by子句会以这种方式与括号交互?

4

1 回答 1

0

order by如评论中所述,子查询中不允许使用。将select括号括起来使 SQL 将其解释为子查询。

于 2015-06-08T17:07:30.957 回答