我需要输出看起来像这样: 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
么?
答案 0 :(得分: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