mysql日期date类型数据比较大小

write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.
+---------+------------------+------------------+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
+---------+------------------+------------------+
|       1 |       2015-01-01 |               10 |
|       2 |       2015-01-02 |               25 |
|       3 |       2015-01-03 |               20 |
|       4 |       2015-01-04 |               30 |
+---------+------------------+------------------+
 return the following Ids 
+----+
| Id |
+----+
|  2 |
|  4 |
+----+
select w1.id from weather w1,weather w2 where to_days(w1.recorddate)
-to_days(w2.recorddate)=1 and w1.temperature>w2.temperature;

利用to_days,将日期之间变得可以比较,即2001-10-01  -   2001-09-30 =1

即,日期被当成整数进行比较了!

你可能感兴趣的:(mysql)