2013-04-09 2 views
3
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가 표시되기를 원합니다.그룹이없는 최대 SQL 서버

 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 
+2

동일한 시작 시간에 두 개의 쿼리 시간이 같으면 어떤 결과를보고 싶습니까? – Mark

+0

callid가 호출중인 경우에는 Select와 StartTime 앞에 CallID를 추가하면됩니다. –

답변

2
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 
0
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 
0

그리고이 시도 :

하는 CallID을 선택 , 상영 시간, 종료 시각, QueryTime
dbo.Calls에서 CLL
같은 여기서 CLL.QueryTime =

(여기서 dbo.Calls.StartTime = CLL dbo.Calls에서 상위 1 dbo.Calls.QueryTime 선택. dbo.Calls.QueryTime 내림차순으로 상영 순서) CLL.StartTime에 의해 CLL.CallID, CLL.StartTime, CLL.EndTime, CLL.QueryTime
순서에 의해

그룹 -이 라인을 거부 할 수 있습니다