Quantcast
Channel: Convert date in date list condition to list of date ranges - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by RolandoMySQLDBA for Convert date in date list condition to list of date ranges

$
0
0

SUGGESTION #1

SELECT A.* FROM table1 A INNER JOIN(    SELECT '2015-03-01' dtcolumn    UNION SELECT '2015-03-15'    UNION SELECT '2015-04-01'    UNION SELECT '2015-04-15'    UNION SELECT '2015-05-01') B ONA.dtcolumn >= B.dtcolumnAND A.dtcolumn < B.dtcolumn + INTERVAL 1 DAY;

SUGGESTION #2

SELECT * FROM table1 WHERE(column >= '2015-03-01' ANDcolumn < '2015-03-01'+ INTERVAL 1 DAY)UNIONSELECT * FROM table1 WHERE(column >= '2015-03-15' ANDcolumn < '2015-03-15'+ INTERVAL 1 DAY)UNIONSELECT * FROM table1 WHERE(column >= '2015-04-01' ANDcolumn < '2015-04-01'+ INTERVAL 1 DAY)UNIONSELECT * FROM table1 WHERE(column >= '2015-04-15' ANDcolumn < '2015-04-15'+ INTERVAL 1 DAY)UNIONSELECT * FROM table1 WHERE(column >= '2015-05-01' ANDcolumn < '2015-05-01'+ INTERVAL 1 DAY);

Viewing all articles
Browse latest Browse all 4

Trending Articles