Skip to content
Advertisement

How to merge SQL Select queries?

I have three queries executed consistently:

I want to combine this three queries into one and query sites 18, 3, 4 via one select, but I don’t see how. Please advise how to merge this 3 queries into one. Any help will be appreciated!

Advertisement

Answer

You seem to want the maximum value for three different sites on the last day in February that has their data.

If so, this is simpler:

Actually, February in 2020 has 29 days. Perhaps you want the entire month; if so, then use '2020-03-01' for the second comparison.

Note that the manipulations on the date/time values are only on the “constant” side. This allows the query to use an index on tstamp if an appropriate index is available.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement