mysql - Selecting a COUNT of values, grouped by that same column, distinct on another -
here's sample schema:
| type_id | university_id | --------------------------- | 1 | u01 | | 2 | u01 | | 2 | u01 | | 3 | u02 | | 4 | u02 | and want count of amount of records have same university_id, university_id itself, , must not include duplicates of type_id, result same data given above:
| university_id | count(university_id) | ---------------------------------------- | u01 | 2 | | u02 | 2 | right i'm trying following, give me count(u01) of 3 instead of 2
select university_id, count(university_id) table group university_id is possible want, , if how?
you should count type_id uniquely not university_id
select university_id, count(distinct type_id) totalcount tablename group university_id
Comments
Post a Comment