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

node.js - StackOverflow API not returning JSON -

python - Subclassed QStyledItemDelegate ignores Stylesheet -

php - Laravel 4.1 to Heroku: SQLSTATE[HY000] [2002] No such file or directory -