Search Posts

Get count of multiple table records with group by function

how to – Get count of multiple table records with group by function

I have 2 tables : priority_list and priority_list_delete

I want to get the following data in a single row:

1) Sum of these 2 table records

2) Count of individual table records

3) Count of priority_list_delete table records category wise

This is what I have done so far:

(SELECT COUNT(*) FROM priority_list)+(SELECT COUNT(*) from 
priority_list_delete) as tot_count,
(SELECT COUNT(*) FROM priority_list) as prior_cnt,
(SELECT COUNT(*) FROM priority_list_delete) as prior_del_cnt

The above query returns the count of the tables but when I merge the below query with the above one, it throws an error:

(SELECT category, COUNT(*) FROM priority_list_delete group by category)

I guess, there is some syntax error which I am unable to sort it out and moreover I am not getting idea about how to get the count records category wise where category names will be the column name.

Example format:

 tot_count| prior_cnt| prior_del_cnt| ST   | OBC
 920      | 893      | 27           | 64   | 100

Here ST and OBC are the categories.

Any help would be appreciated.

Thanks in advance.

Source: Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *