sql - How to count records for each day in a range (including days without records) -


i'm trying refine question little since didn't ask correctly last time. doing query:

select count(orders) orders_table order_open_date<=to_date('##/##/####','mm/dd/yyyy') , order_close_date>=to_date('##/##/####','mm/dd/yyyy') 

where ##/##/#### same day. in essence query designed find number of 'open' orders on given day. problem i'm wanting each day of year or more. think if knew how define ##/##/#### variable , grouped count variable work i'm not sure how that-or there may way well. using oracle sql on sql developer. input.

you use "row generator" technique (edited hogan's comments):

select rg.day,        count(orders)   orders_table,       (select trunc(sysdate) - rownum day         (select 1 dummy dual)        connect level <= 365       ) rg rg.day              <=to_date('##/##/####','mm/dd/yyyy')   , rg.day              >=to_date('##/##/####','mm/dd/yyyy')   , order_open_date(+)  <= rg.day   , order_close_date(+) >= rg.day - 1 group rg.day order rg.day 

this should list each day of previous year corresponding number of orders


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -