简体   繁体   English

sql newbie:多变量分组和聚合

[英]sql newbie: multi variable grouping and aggregation

the raw data looks like this 原始数据如下所示 在此处输入图片说明

I want to transform this so I could know for each country_code, how many people register with facebook, and how many register with email. 我想对此进行转换,这样我才能知道每个country_code,有多少人在facebook上注册以及有多少人在电子邮件上注册。

like: 喜欢:

country_code|facebook|email
---------------------------
AE          |  4     | 5
AL          |  11    | 10

thanks! 谢谢!

You can use sum with case and group by : 您可以将sumcasegroup by

select country_code,
    sum(case when register_with = 'facebook' then 1 else 0 end) facebook,
    sum(case when register_with = 'email' then 1 else 0 end) email
from yourtable 
group by country_code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM