I am coding in Python. I have query like this:
SELECT device_os, count(*) FROM warehouse WHERE device_year <= 2016 GROUP BY device_os;
Now, I have some additional filters which are coming dynamically from the user. For example,
device_id IN (15, 85, 65) OR device_model in ('MAX', 'SHARP', 'AD')
I have these extra conditions which I want to apply to the query. So, the final query should become:
SELECT device_os, count(*) FROM warehouse WHERE device_year <= 2016 AND (device_id IN (15, 85, 65) OR device_model in ('MAX', 'SHARP', 'AD')) GROUP BY device_os;
I have searched about sqlparse
but has not been successful. How can I make it look like what I want?