Make the Google Sheets QUERY function even more flexible when you add variable parameters to your query.
Using Text Fields as Variable Fields
The syntax is essentially a combination of single quotes, double quotes, and the ampersand symbol. This is the basic syntax:
=Query(A1:B10,"Select * where B = '"&A1&"'")
Here’s an example:
Using Number Fields as Variable Fields
The syntax is almost the same as using text fields, however you will only use double quotes and the ampersand.
=Query(A1:B10,"Select * where B = "&A1&"")
Using Dates as Variable Fields
Dates are tricky because the format has to be in ISO format (YYYY-MM-DD) for it to work properly as a filter. The default format in Google Sheets is M/D/YYYY so you can use this as your WHERE clause to change the formatting:
=QUERY(A1:B10,"Select * WHERE B = date '"&TEXT(DATEVALUE("5/1/2020"),"yyyy-mm-dd")&"' ")
Or if you want to use a cell reference for your date you can use this:
=QUERY(A1:B10,"Select * WHERE B = date '"&TEXT(DATEVALUE(C1),"yyyy-mm-dd")&"' ")