I don’t think this is possible but I wanted to make sure.
Lets say I wanted to get the average age of users assuming some conditions.
SELECT avg(age) as avg_a FROM users where something something;
Now the say the client wants to get average age, average age for male and average age for female.
so something like
SELECT avg(age) as avg_a, avg(age where female) avg_f, avg(age where male) avg_m FROM users where something something;
Is something like this even possible or even wise?
How would I go about doing it? Or should I just run 3 queries every time?
Yes, you can use a case statement within your aggregation function. See: