SUM and COUNT SQL QUERY to display Number of Counts of Registered, Rejectected, Active and Total Number of Registered Users from Database
Today i want to teach you that how u can get total number of Registered Students, Active Students and Blocked Students. Before starting i Just want to show you that i have table known as users_table in data base and i have table structure like below given picture;
I above given table i have total 4 registered users and out of 4 only 2 users or Active, 1 is in pending, 0 Rejected and 1 Users Account Status is Blocked here we have query to get this result.
sqlQuery = "select sum(case when status = 'Active' then 1 else 0 end) active," +
" sum(case when status = 'Rejected' then 1 else 0 end) rejected," +
" sum(case when status = 'Blocked' then 1 else 0 end) blocked," +
" sum(case when status = 'Pending' then 1 else 0 end) pending," +
"count(*) total from users_table";
Remember that Here my database table name is users_table and column name is status, but you can change it according to your table name and coloumn Name.....
0 Comments