database - MySQL: Get all rows if specific value reached after date -
in mysql, want find rows value of column went 0 after specific date.
so, given data:
cat value date 95 2015-09-01 78 2015-10-01 0 2015-11-01 0 2015-12-01 b 129 2015-09-01 b 230 2015-10-01 b 201 2015-11-01 b 140 2015-12-01 in case, want run query asks:
which categories have 0 value after 10/1/2015 , had positive value before 11/1/2015?
the result should show category "a".
i suspect nested select statement, haven't quite figured out.
select * yourtable value = 0 , date > '2015-10-01' , cat in ( select distinct cat value > 0 , date < '2015-11-1' ) explanation: can split query 2 parts - inner query in statement in charge of getting cat id's positive before 11/1/15, , where value = 0 , date > '2015-10-01' give 0 after 10/1/15
Comments
Post a Comment