SQL语法问题

时间:2010-10-19 15:12:21

标签: sql sql-server select

我不能为我的生活弄清楚这个sql语句有什么问题

select top(1) 
  OrderNumber 
 from (select top(5) 
         OrderNumber 
       from SomeTable
       where TreePath='tests' 
       order by OrderNumber asc) 

任何想法?

此致 Byron Cobb。

1 个答案:

答案 0 :(得分:7)

您需要为派生表添加别名

select top 1 
  myDerivedTable.OrderNumber 
 from (select top 5 
         OrderNumber 
       from TABLE 
       where TreePath='tests' 
       order by OrderNumber asc) myDerivedTable
order by myDerivedTable.OrderNumber