Answer the question
In order to leave comments, you need to log in
How to build a SQL query to get shares depending on the end date?
Figuratively, there should be 2 parts: active and inactive.
It is necessary to fit everything into one request.
Example of received data:
End date (Just ascending dates starting from today):
Answer the question
In order to leave comments, you need to log in
Wouldn't like to use
isActive, because this field will have to be updated every time when accessing promotions
SELECT * FROM special WHERE date_end > NOW()
UNION
SELECT * FROM special WHERE date_end < NOW()
For activity / inactivity, add a calculated field to the query output: DATE(NOW()) <= date_end AS isActive
To group by yesterday / the day before yesterday, you will have to sequentially compare the date with
CASE TRUE
WHEN date_end >= DATE_ADD(NOW(), INTERVAL 1 WEEK))
AND date_end < DATE_ADD(NOW(), INTERVAL 1 MONTH)) THEN "через месяц"
WHEN date_end >= DATE_ADD(NOW(), INTERVAL 1 DAY))
AND date_end < DATE_ADD(NOW(), INTERVAL 1 WEEK)) THEN "через неделю"
...
END AS kogda
and similar
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question