2014-06-12 4 views
0

아래 코드를 바탕으로 max_concrncy 카운트를 분 단위로 계산할 수있는 방법을 알아내는 데 도움이 필요합니다. 현재 쿼리는 매일 카운트를 반환하며 분 카운트를 얻으려고 애쓰는 데 어려움을 겪고 있습니다.postgresql에서 분당 카운트 값 받기

SELECT cast(to_char(date,'MM-DD-YYYY') as date) log_dt ,initcap(url), 
url,count(userid) tot_hits,count(distinct userid) unq_hits, 
count (cast(to_char(date,'MM-01-YYYY hh:mi:00') as date))as max_concrncy 
**// i need max of count (cast(to_char(date,'MM-01-YYYY hh:mi:00') as date)) as max_concrncy here** 

,case when httpstatuscode>=100 and httpstatuscode<=199 then httpstatuscode 
    else null end as sts_cd_100 
,case when httpstatuscode>=200 and httpstatuscode<=299 then httpstatuscode 
    else null end as sts_cd_200 
,case when httpstatuscode>=300 and httpstatuscode<=399 then httpstatuscode 
    else null end as sts_cd_300 
,case when httpstatuscode>=400 and httpstatuscode<=499 then httpstatuscode else null end as sts_cd_400 
,case when httpstatuscode>=500 and httpstatuscode<=599 then httpstatuscode 
    else null end as sts_cd_500 
FROM sp01.apps_log_temp where initcap(url)='/766/sigma/data.Ashx' 
and userid <> '-' group by cast(to_char(date,'MM-DD-YYYY') as date),httpstatuscode 

다음은 쿼리가 반환하는 결과입니다. 강조 표시된 데이터는 max_concrncy 값입니다.이 값은 분당 값을 그룹화 할 때 실제로 알아 낸 25와 14입니다.

date    url   tothit unqhit max_concrncy httpstatuscode 
2014-01-31 /766/sigma/data.Ashx 75 2 **75**   200 
2014-01-30 /766/sigma/data.Ashx 50 1 **50**   200 

입력 데이터 추가.

date   httpstatuscode  url 
2014-01-31 00:01:51 200  /766/sigma/data.ashx 
2014-01-31 00:01:52 200  /766/sigma/data.ashx 
2014-01-31 00:01:52 400  /766/sigma/data.ashx 
2014-01-31 00:25:57 200  /766/sigma/data.ashx 
2014-01-30 00:01:51 300  /766/sigma/data.ashx 
2014-01-30 00:01:52 200  /766/sigma/data.ashx 
2014-01-30 00:01:52 200  /766/sigma/data.ashx 
2014-01-30 00:25:57 200  /766/sigma/data.ashx 

죄송합니다. 귀하의 회신에 감사드립니다.

+1

당신의 질문을 단순화하는 것이 가능합니다. (노이즈를 추가하는 일부 열을 제거 할 수 있다고 생각합니다) 몇 가지 예제 데이터 입력을 제공합니까? –

답변