2014-02-20 2 views
-1

어떻게 내가 아래 쿼리 한마디로찾기 합계는

select DATEPART(month,date) as month ,sum(volume) as Total_Volume 
from traffic_data_replica 
where DATENAME(weekday,date)='sunday' and DATENAME(year,date)=2013 
group by DATEPART(month,date) 
order by DATEPART(month,date); 

, 대한 결과의 합을 찾을 수 있습니다 결과 위의 질의

+1

당신은 결과의 합으로 무엇을 의미합니까? 쿼리에서 반환 한 레코드 수 또는 Total_Volume 합계가 필요합니까? –

+0

검색어에 오류가 있습니까? – Amit

+0

위 쿼리는 결과를 행으로 반환합니다. 합계를 원합니다 – bibinmatthew

답변

2

, 당신은 사용할 수 있습니다

당신이 당신의 현재 쿼리의 행에받을 행으로 계산합니다
SELECT SUM(Total_Volume) 
FROM (
    select DATEPART(month,date) as month , 
    sum(volume) as Total_Volume 
    from traffic_data_replica 
    where 
    DATENAME(weekday,date)='sunday' 
    and DATENAME(year,date)=2013 
    group by DATEPART(month,date) 
    order by DATEPART(month,date) 
) AS Data 

, 당신은 사용할 수 있습니다

SELECT COUNT(*) 
FROM (
    select DATEPART(month,date) as month , 
    sum(volume) as Total_Volume 
    from traffic_data_replica 
    where 
    DATENAME(weekday,date)='sunday' 
    and DATENAME(year,date)=2013 
    group by DATEPART(month,date) 
    order by DATEPART(month,date) 
) AS Data 
+0

에 의해 DATENAME (평일, 날짜) = '일요일'및 DATENAME (년, – bibinmatthew

0

같은 것을 시도에 의해 반환 된 결과의 합 당신이 당신의 현재 쿼리의 행에받는 모든 Total_Volume의 합을 원하는 경우에

SELECT COUNT(*) FROM 
(
    select DATEPART(month,date) as month ,sum(volume) as Total_Volume 
from traffic_data_replica 
where DATENAME(weekday,date)='sunday' and DATENAME(year,date)=2013 
group by DATEPART(month,date) 
order by DATEPART(month,date) 
) AS subquery;