2013-09-25 27 views
0

我有這樣的MySQL表比較:採取從最後14天的數據,並與最新的7天

typ | user | data | value 

typ = what type of data 
user = whos the user 
data = date the data was inserted 
value = value inserted 

所以這個表是我的cronjob自動更新。通常,一個用戶在這個表中會有多個行,因爲它會爲每個新的一天插入一個新行,如果日期與今天相同,則更新當前行。

我需要從最新的14天內獲取數據,並將它們與最近7天的數據進行比較。

7 | admin | 2013/09/22 | 3412 
7 | admin | 2013/09/23 | 1241 
7 | admin | 2013/09/24 | 2419 
and so on... 

這就是結構。

我怎樣用PHP從最近的14天內獲取數據?然後從最近的7天?

我不確定如何做到這一點。

+0

你應該發佈你已經嘗試過的代碼 –

回答

0
select * from your_table 
where curdate() - interval 14 day >= data 

select * from your_table 
where curdate() - interval 7 day >= data