Reputation: 117
I have a database with a lot of dates. I need to create a query that can help me make a dataframe of the dates I'm interested in. I need to select the dates from 25 to 31 october, without selecting specific years. I currently only have this, selecting only one date
query_week = '''
SELECT [ID]
FROM dates
WHERE [ID] IN
(Select [ID]
FROM movies
WHERE Genre = 'Horror'
AND (Date LIKE \"%-10-25\"));
'''
Thanks in advance.
Upvotes: 2
Views: 79
Reputation: 14216
Your query should look like this:
query_week = """
SELECT [ID]
FROM dates
WHERE [ID] IN
(Select [ID]
FROM movies
WHERE Genre = 'Horror'
AND MONTH(CAST([Date] AS DATE)) = 10
AND DAY(CAST([Date] AS DATE)) BETWEEN 25 AND 31);
"""
Keep in mind date
is a reserved keyword in SQL so you will have to format it accordingly to whatever flavor of SQL you are using.
Upvotes: 1