简体   繁体   中英

Take data from last 14 days and compare with the latest 7 days

I have this MySQL table:

typ | user | data | value

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

So this table is updated automatically in my cronjob. Usually one user will have multiply rows in this table, since it will insert a new row for each new day and update the current row if the date is the same as today.

I need to take data from the latest 14 days and compare them with the data from the latest 7 days.

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

This is how the structure is.

How can I, with PHP, get the data from the latest 14 days? And then from the latest 7 days?

I'm unsure on how to do this.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM