sql server - Join 2 tables and Count the number of occurrence specific field in SQL -
i have 2 tables , "t_common_country" , "t_hei_studentdata." using left join joined these tables
this query
select [t_common_country].[country_id], [t_common_country].[country], [t_hei_studentdata].[student_id] ([t_common_country] left join [t_hei_studentdata] on [t_common_country].[country] = [t_hei_studentdata].[stdcountry])
now i' getting view
| country id | county | student id | | 1 | usa | 12 | | 1 | usa | 5 | | 2 | uk | 11 | | 2 | uk | 2 |
i want count number of students (student_ids) relate country ,
i want view below
| country id | county | students | | 1 | usa | 2 | | 2 | uk | 2 |
use count
function generate countrywise student count
try this:
select c.[country_id], c.[country], count(s.[student_id]) studentcount [t_common_country] c left join [t_hei_studentdata] s on c.[country] = s.[stdcountry] group c.[country_id], c.[country];
Comments
Post a Comment