sql - Select all dates between two dates and display the unique count of inventory id -


im using oracle db .i have 2 table inventory , grounding_info . each inventory can have multiple grounding info or none. table structure follows.

inventory ---------               inventory_id   grounding_info -------------- info_id inventory_id grounding_date 

i want count of inventories grounded on each date between given date range. if no inventory grounded on date , date should displayed count 0.

please help.. tried below query:

select tble.dte,count(distinct(groundinginfo.inventory_id)) cmt atl_grounding_info groundinginfo outer join (     select to_date('2015/01/01 12:00:00 a.m.' ,'yyyy/mm/dd hh:mi:ss a.m.') - 1 + rownum dte all_objects groundinginfo     to_date('2015/01/01 12:00:00 a.m.' ,'yyyy/mm/dd hh:mi:ss a.m.') - 1 + rownum <= to_date('2015/04/01 11:59:59 p.m.' ,'yyyy/mm/dd hh:mi:ss p.m.')  ) tble on groundinginfo.date_turned_in = tble.dte group tble.dte 

but returned error: "ora-00933: sql command not ended"

try query:

select tble.dte, count(distinct inventory_id) cmt atl_grounding_info groundinginfo right join (     select trunc(to_date('2015/01/01' ,'yyyy/mm/dd') - 1 + rownum) dte dual     connect rownum < 366 , trunc(to_date('2015/01/01' ,'yyyy/mm/dd') - 1 + rownum) <= trunc(to_date('2015/04/01' ,'yyyy/mm/dd')) ) tble on tble.dte = trunc(groundinginfo.date_turned_in) group tble.dte order tble.dte asc 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -