开发者

Selecting dates next to each other in Mysql

Been trying to figure this out for a while now.

I am looking to select rows from a database table in MySQL where the two dates are next to each other.

开发者_如何学编程

e.g. 2011-07-20 is next to 2011-07-21.

Many Thanks

Neil


I guess you can JOIN using ADDDATE():

SELECT T1.id, T2.id
FROM myTable AS T1
INNER JOIN myTable AS T2
    ON T1.DATE = ADDDATE(T2.DATE, -1)
WHERE T1.id < T2.id;

The WHERE is to verify that T1 and T2 don't contain duplicates.


SELECT * FROM table WHERE date_column BETWEEN '2011-07-20' AND DATE_ADD('2011-07-20', INTERVAL 1 day)

Manual:
between operator
date_add function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜