Select records from today, this week, this month php mysql

前端 未结 11 863
粉色の甜心
粉色の甜心 2020-12-12 10:50

I imagine this is pretty simple, but can\'t figure it out. I\'m trying to make a few pages - one which will contain results selected from my mysql db\'s table for today, thi

11条回答
  •  佛祖请我去吃肉
    2020-12-12 11:22

    Assuming your date column is an actual MySQL date column:

    SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY score DESC;        
    SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 WEEK) ORDER BY score DESC;
    SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY score DESC;
    

提交回复
热议问题