我有以下表命名staff_status
,結構和記錄:MySQL查詢得到記錄的具體日期
----------------------------------------------------
| id (INT) | status (VARCHAR) | status_date (DATE) |
----------------------------------------------------
| 1 | Working | 2009-05-03 |
| 2 | Working | 2009-07-21 |
| 1 | Leave | 2010-02-01 |
| 1 | Working | 2010-02-15 |
----------------------------------------------------
現在我想查詢它來獲取員工的status
在特定的日期。示例:id = 1
上2010-02-10
狀態應該返回Leave
同時2010-03-01
應該返回Working
什麼我都沒有成功嘗試:
SELECT t1.status FROM staff_status t1 INNER JOIN (SELECT * FROM staff_status WHERE id = 1 AND status_date < '2010-02-10') t2 ON (t1.id = t2.id AND t1.status_date < t2.status_date);
到目前爲止你做了什麼? – diEcho 2012-08-10 06:05:16
已更新,嘗試查詢 – 2012-08-10 06:07:37
爲什麼你還要加入,如果你只想知道status_date和id時的狀態? – NewInTheBusiness 2012-08-10 06:13:19