MySQL Forums
Forum List  »  Newbie

Sums for Last MTD and YTD produce multiple rows
Posted by: Scot Kubiak
Date: December 07, 2016 03:18PM

Hi,

I am trying to obtain sums for Last 24 hrs, MTD and YTD using the following SQL. The Last 24hrs produces a single row which is what I would expect. However, when I add in the MTD and YTD I receive multiple rows. I imagine I have a simple error in my code. Any ideas?

select (select sum(TOTAL_MINS_OUTAGE) from INCIDENTS
where SERVICE_CUSTOMER_FINANCIAL_SERVICE_SUBCAT_CIM='On'
and OPEN_DATE>= date(now()) - interval 1 Day) as Last_24,
(select distinct sum(TOTAL_MINS_OUTAGE) from INCIDENTS where
SERVICE_CUSTOMER_FINANCIAL_SERVICE_SUBCAT_CIM='On' and
year(curdate()) =year(OPEN_DATE) and month(curdate()) = month(OPEN_DATE)) as MTD,
(select sum(TOTAL_MINS_OUTAGE) from INCIDENTS where
SERVICE_CUSTOMER_FINANCIAL_SERVICE_SUBCAT_CIM='On' and
year(curdate()) =year(OPEN_DATE)) as YTD
from INCIDENTS;

Options: ReplyQuote


Subject
Written By
Posted
Sums for Last MTD and YTD produce multiple rows
December 07, 2016 03:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.