MySql Query to select over a range of dates -


i have table contains:

line | date | metricname | metricvalue 

i want select date > curdate() - 30 days

-condition each record

where metricname = "foo" , metricname != "bar"(metric value has never been "bar").

essentially in entire span of time if metricvalue ever did = "bar" dont want see line.

this should exclude of lines consideration. hope line primary key. or better yet, table indexed on?

select   `line`   `the_table`   `date` > now() - 'your interval' ,   `metricname` = 'foo' ,   `line` not in (     select distinct `line` `the_table` `metricname` = 'foo' , `metricvalue` = 'bar'   ) 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -