I have the following query in python, which I use via pd.read_sql_query. It works fine. I have a list of dates, called dates, that I use for the query.
for date i in dates:
query = ('SELECT * FROM table WHERE id in'+ str(tuple(ids)) + ' AND date
between '+"'"+str(i)+"'"+' and '+"'"+str(i)+"'")
Is there an easier way to query the dates, such as the ids? I would like to have something like this:
query = ('SELECT * FROM table WHERE id in'+ str(tuple(ids)) + ' AND date in' + str(tuple(dates)) + "'")
However, this does not work because dates are saved as timestamp in my python list as well as in the sql database.
my sql data looks the following:
id date variable
A 20180101 00:00:00 1
B 20180101 00:00:00 2
B 20180501 00:00:00 3
C 20180201 00:00:00 4
I have a list of ids formatted as strings:
["B", "C"]
And a list of dates, formated as datetime64[ns]:
[20180101 00:00:00, 20180201 00:00:00]
The desired output is:
id date variable
B 20180101 00:00:00 2
C 20180201 00:00:00 4