SQLTeam.com | Weblogs | Forums

Counting daily into monthly via nested select statement


#1

hello, i'm using SQL - via Oracle Toad 12 and i need some help with my code.
i'm relatively new to SQL - i can do the most basic things, but this one is a little bit more complicated.
hoping someone can let me know what i'm doing wrong.

the inner SELECT statement works perfectly, but when i try to sum up the initial daily select statement into a monthly one i run into trouble

SELECT

trunc(Day, 'yyyy-mm') as "Month",
sum(frequency)

FROM

(SELECT

to_char(DATETIME, 'yyyy-mm-dd') as "Day",
count(distinct(CUSTOMER_ID)) as Frequency

FROM

ORDERS

WHERE

DATETIME BETWEEN TO_DATE ('2017-01-01', 'yyyy-mm-dd') AND TO_DATE ('2017-07-31', 'yyyy-mm-dd')

Group by
to_char(DATETIME, 'yyyy-mm-dd'))

Group By
trunc(Day, 'yyyy-mm')


#2

This is a SQL Server forum. Therefore, you will likely get better responses to your q from a different, more Oracle-based forum.