0

我需要我的输出看起来像这样:ClientID、Session、Duration、TimeStamp_Start、TimeStamp_End

这是我的查询到目前为止的样子:

SELECT     ClientID, Session, Duration, MIN(TimeStamp) AS TimeStamp_Start, MAX  
(TimeStamp) AS TimeStamp_End
FROM         dbo.tblHistory
WHERE     (TimeStamp >= DATEADD(yy, - 1, GETDATE()))
GROUP BY ClientID, Session, Duration

我得到了这个输出。

zsw@sdfs  00000020  0     2013-08-13 13:18:58.000  2013-08-13 13:18:58.000
zsw@sdfs  00000020  16112 2013-08-13 17:47:30.000  2013-08-13 17.47.30.000

我希望输出看起来像这样

ClientID  Session  Duration  TimeStamp_Start          TimeStamp_End

zsw@sdfs  00000020  16112  2013-08-13 13:18:58.000  2013-08-13 17.47.30.000

建议?

4

1 回答 1

1
SELECT     ClientID, Session, SUM(Duration), MIN(TimeStamp) AS TimeStamp_Start, MAX  
(TimeStamp) AS TimeStamp_End
FROM         dbo.tblHistory
WHERE     (TimeStamp >= DATEADD(yy, - 1, GETDATE()))
GROUP BY ClientID, Session
于 2013-08-27T17:32:58.513 回答