I have been trying to generate report as per age differences of different months the solution currently i know is to make separate sql queries for each month and each age difference separately which results to create 4 different sql queries for each month. Kindly let me know is it possible to create one sql query for each month like
If i want to generate report for JAN for age differences of Above 40, In Between 50 – 60, In between 60-70 and above 80
How can i put it in one sql queries and get four different results from it
Something like (an idea only)
Select count(Above 40),count(In Between 50 - 60),count (In B/W 60-70), count(above 80) from users
I’d use the IF() and SUM() together as follows:
Refer to the MySQL explanation for IF(expr1,expr2,expr3), but basically expr1 is the condition, expr2 is the value when the condition is true and expr3 is the else. Using 1 & 0 for these allows the SUM() to count the records.