sql - Show gaps between dates in MySQL -


how can show remaining/complementary dates in mysql?

for example in table has 2 columns, snapshot
from_date>14-06-2014 , to_date<01-07-2014

would give output:

from date   || to_date 15-06-2014  || 20-06-2014 23-06-2014  || 27-06-2014  29-06-2014  || 30-06-2014  

i able show dates have gap , no records exist, this:

2 //21-06-2014 - 23-06-2014 1 //28-06-2014  

is possible? thank you

along lines:

drop table if exists dates; create table dates (d_from date, d_to date); insert dates values  ('2014-06-15'  , '2014-06-20'), ('2014-06-23'  , '2014-06-27' ), ('2014-06-29'  , '2014-06-30' );  select low.d_to, high.d_from, to_days(high.d_from) - to_days(low.d_to) - 1 gap  dates low, dates high high.d_from = (select min(d_from) dates d_from > low.d_to) ; 

which means: join table on adjacent end/start dates , compute difference.

+------------+------------+------+ | d_to       | d_from     | gap  | +------------+------------+------+ | 2014-06-20 | 2014-06-23 |    2 | | 2014-06-27 | 2014-06-29 |    1 | +------------+------------+------+ 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -