MySQL-> Multiple same values from a field will be sum and the new field name will be as how I define

Question Explanation : There is a table named people and there is information stored of different people from different country. Now how we can we see how many people form Bangladesh,Canada,Italy or few others country as table view ?

SELECT
SUM(CASE WHEN country_name ='Bangladesh' THEN 1 ELSE 0 END) as Bangladesh,
SUM(CASE WHEN country_name ='Canada' THEN 1 ELSE 0 END) as Canada
from people;

Comments

Popular posts from this blog

WP register_post_type() with custom CMB2 meta box

Git post receive setup at server for git push to the production from local machine