date - How to find a lifespan of a name in MySQL? -
i have sql table containing series of ids , dates that id registered in system. 1 id can registered several time. table below :
id date 3 16/6/2009 4 2/4/2010 7 4/9/2012 3 12/6/2009 7 2/8/20011 3 16/12/2009 etc..
from table like extract ids lifespan (i want subtract firstseen date , lastseen date).ids can have same date , id can registered in different days.
do knows query should use required result below?
id date(week) 3 2/4/2009-16/6/2009 4 2/4/2010 7 2/8/20011-4/9/2012
select x.id , x.start ( select id , min(date) start my_table group id ) x left join ( select id , max(date) end my_table group id ) y on y.id = x.id , y.end > x.start;
Comments
Post a Comment