0

我正在尝试按如下方式检索每个客户的最后销售日期,但它只是返回表中的最后一个条目:

Select top 1 InvoiceDate
,Customer
from salestable a
order by InvoiceDate desc

帮助将不胜感激。

4

1 回答 1

1

不要使用TOP 1- 这就是你只返回 1 个结果的原因。

尝试使用MAXGroupBy客户

SELECT Customer, MAX(InvoiceDate)
FROM SalesTable
GROUP By Customer
ORDER By MAX(InvoiceDate) DESC
于 2013-06-26T10:47:14.840 回答