I have a table with some columns, one holds a timestamp that I use to run
currently four single selects to compute a SELECT count() and return information
like “n-rows older than 1 week”, “n-rows older than 2 weeks”, …
How to transform the four queries into one SQL-Statement that is hopefully
running faster?
The statements look like this:
SELECT count(foo_pk) AS oneweek FROM foo WHERE foo_timstamp < DATE_SUB(now(), INTERVAL 1 week)
I’m not a MySql guy, but in SQL Server I would use the CASE statement like so:
It seems that this statement is available in MySql as well, so while my syntax might be a bit off I think something like the SQL above should work.