CallID StartTime EndTime Querytime
1692 2012-11-20 11:52:00.000 2012-11-20 11:52:00.300 0.300
1693 2012-11-20 11:52:00.000 2012-11-20 11:52:00.100 0.100
1694 2012-11-20 11:52:00.000 2012-11-20 11:52:00.400 1.5
1695 2012-11-20 11:52:01.000 2012-11-20 11:52:01.400 3
1696 2012-11-20 11:52:01.000 2012-11-20 11:52:01.300 5我希望获得按StartTime分组的最大查询时间,如下所示,但我仍然希望显示CallID。
StartTime MaxQueryTime
2012-11-11 19:04:07.000 0.300
2012-11-11 19:04:10.000 0.200
2012-11-11 19:08:48.000 0.300
2012-11-11 19:08:51.000 0.300
2012-11-11 19:09:27.000 0.100
SELECT StartTime, MAX(Querytime) AS QueryTime
FROM dbo.Calls
GROUP BY StartTime发布于 2013-04-09 22:38:04
WITH records
AS
(
SELECT CallID, StartTime, EndTime, QueryTime,
DENSE_RANK() OVER (ORDER BY QueryTime DESC) rn
FROM TableName
)
SELECT CallID, StartTime, EndTime, QueryTime
FROM records
WHERE rn = 1发布于 2013-04-09 22:52:44
select CallID, StartTime, max(QueryTime) over (partition by StartTime) as QueryTime
from (
SELECT CallID, StartTime, MAX(Querytime) as QueryTime
FROM dbo.Calls
GROUP BY CallID, StartTime
) t发布于 2013-04-11 03:50:01
然后试试这个:
选择CallID、StartTime、EndTime、QueryTime
从dbo.Calls作为CLL
where CLL.QueryTime = (Select top 1 dbo.Calls.QueryTime from dbo.Calls where dbo.Calls.StartTime = CLL.StartTime order by dbo.Calls.QueryTime desc ) group by CLL.CallID,CLL.StartTime,CLL.EndTime,CLL.QueryTime
order by CLL.StartTime --您可以拒绝此行
https://stackoverflow.com/questions/15904867
复制相似问题