0

我正在尝试查询具有这些参数的数据库:

Transaction Date, User Email Address

我想要的结果表是这些参数:

Email Address, dateDiff

对于 dateDiff,我想找出最早交易日期和最晚交易日期之间的差异。

我该怎么做呢?

我的代码(显然不正确)

SELECT [Email Address], DATEDIFF(day, [Transaction Date],[Transaction Date]) AS 'dateDiff'
FROM [DB].[TABLE]
ORDER BY [dateDiff] Desc
4

1 回答 1

4

在执行以下操作之前,您需要聚合以获取每封电子邮件的最小值和最大值datediff()

SELECT [Email Address],
       DATEDIFF(day, min([Transaction Date]), max([Transaction Date])) AS 'dateDiff'
FROM [DB].[TABLE]
GROUP BY [Email Address]
order by 2 desc;
于 2013-08-07T22:31:27.560 回答