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;
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
Post a Comment