sql - use for COUNT command to create query in MYSQL -


below shows original sql table.

select name, count(city) "count_no" emp group name order count_no desc; 

enter image description here

i need following result.

enter image description here

sam has 4 records. there city of london in 2 records. need how many different cities in sam's records. did lots of queries, couldn't create sql query.

add distinct count parameter:

select name, count(distinct city) "count_no" emp group name order count_no desc; 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -