mySQL SELECT upcoming birthdays

前端 未结 17 676
我寻月下人不归
我寻月下人不归 2020-12-03 11:17

I\'m trying to write a query to select users of a database whose birthdays are in the next 7 days.

I\'ve done a lot of research but I can\'t come up with a working s

17条回答
  •  猫巷女王i
    2020-12-03 11:42

    I did a lot "researches" and here is my solution, I guess it is very easy to understand!

    SELECT *,
    (366 + DAYOFYEAR(birth_date) - DAYOFYEAR(NOW())) % 366 as left_days
    FROM `profile`
    ORDER BY left_days;
    

提交回复
热议问题