SQL select dates in future and not ending before until date
I want to select shows that are only in the future but also shows are are currently in progress. This must be a common request but I couldn't find any info on helping me solve this problem.
My tables has date columns: - show_from - show_until
SELECT * FROM shows s
WHERE s.show_status = 'ENABLED'
AND s.show_from >= CURRENT_DATE()
ORDER BY s.show_from ASC
This se开发者_开发百科lects the shows in the future but if a show last for more than 1 day it will not be displayed.
SELECT * FROM shows s
WHERE s.show_status = 'ENABLED'
AND
(
s.show_from >= CURRENT_DATE()
OR (s.show_from <= CURRENT_DATE() AND s.show_until >= CURRENT_DATE())
)
ORDER BY s.show_from ASC
To select shows that have started but not yet finished.
try this :
SELECT * FROM shows s
WHERE s.show_status = 'ENABLED'
AND s.show_to >= CURRENT_DATE())
ORDER BY s.show_from ASC
Does this work?
SELECT * FROM shows s
WHERE s.show_status = 'ENABLED'
AND (s.show_from >= CURRENT_DATE() OR s.show_to >= CURRENT_DATE())
ORDER BY s.show_from ASC
精彩评论