sql - Sum the differences between dates -
i have 2 tables, master , detail, both contain dates related events. first contain master record's begin , end date. second contains various gaps, have beginning , end, related master record , falling between begin , end date. can calculate total number of days between master record's start , end but, yet i'm failing see how can aggregate sum of "off days" in details table , group them month. mean:
master table
start date (mm/dd/yyyy): 01/01/2015 end date (mm/dd/yyyy): 01/25/2015
total number of days: 25
details table
start date (mm/dd/yyyy) | end date (mm/dd/yyyy) : 01/02/2015 | 01/05/2015 01/09/2015 | 01/15/2015 01/18/2015 | 01/19/2015
total number of "off days": 13
the db environment oracle 11g. can me?
try :
select sum(end_date-start_date+1) details_table;
the sum function sum total of dates, should give 13 "off days" wanted.
if want add start_date/end_date conditions, can this.
select sum(end_date-start_date+1) details_table start_date>=to_date('01/01/2015','mm/dd/yyyy') , end_date<=to_date('01/25/2015','mm/dd/yyyy');
Comments
Post a Comment