1
 SELECT OrderNumber, FIRST(ShippingName) as ShippingName FROM Orders
 GROUP BY OrderNumber

这给出了一个错误,我该怎么做?

4

2 回答 2

4

FIRSTSQL Server 不支持该函数。

也许你想要

SELECT OrderNumber, MIN(ShippingName) as ShippingName
FROM Orders
GROUP BY OrderNumber

但是,可能不会。相反,我怀疑您的意思是...对于每个OrderNumber, 在所有带有 that 的行中,根据某些顺序OrderNumber选择第一行的 。ShippingName

SELECT OrderNumber,
    (
        SELECT TOP 1 ShippingName
        FROM Orders AS OrdersInner
        WHERE OrdersInner.OrderNumber = Orders.OrderNumber
        ORDER BY OrdersInner.OrderDate, OrdersInner.OrderId
    ) as ShippingName
FROM Orders
GROUP BY OrderNumber

但我正在对您的要求和数据库结构做出一些假设。

于 2012-05-24T16:36:50.693 回答
0

你可能的意思是:

SELECT TOP 1 OrderNumber, ShippingName
FROM Orders
ORDER BY OrderNumber DESC
于 2012-05-24T16:39:12.397 回答