0
我的目標是GROUP (eid) sort by dayatime() pick the first 2 times in each group, cal the day difference.
如何計算同一事件
一天deffirence我知道的想法,但我怎麼可能轉化爲真正的MySQL查詢語法?
mysql> select * from events;
+------+------------+
| eid | dt |
+------+------------+
| 1 | 2013-01-01 | -> 3
| 1 | 2013-01-04 | -> 1
| 1 | 2013-01-05 |
| 2 | 2013-04-01 | -> 7
| 2 | 2013-04-08 |
+------+------------+
5 rows in set (0.00 sec)
GOAL: query that gives this result:
+------+------------+-----------------+
| eid | dt | days_until_next |
+------+------------+-----------------+
| 1 | 2013-01-01 | 3 |
| 1 | 2013-01-04 | 1 |
| 2 | 2013-04-01 | 7 |