这是我的桌面拍摄
我需要下面的结果 -
我使用了以下查询
select date(added_datetime),
(select count(social_network) from social_user where social_network = 'FBuser') as FB,
(select count(social_network) from social_user where social_network = 'LIuser') as LI,
(select count(social_network) from social_user where social_network = 'TWuser') as TW,
(select count(social_network) from social_user where social_network = 'GPuser') as GP
from social_user group by MONTH(added_datetime)
我没有得到我的预期结果。
请帮帮我
对不起我的英语,我没有足够的声誉,这就是为什么我无法附上样本图片
答案 0 :(得分:2)
你可以做条件和
select
concat(date(added_datetime),MONTH(added_datetime)) as `Year_month`,
sum(social_network = 'FBuser') as FB,
sum(social_network = 'LIuser') as LI,
sum(social_network = 'TWuser') as TW,
sum(social_network = 'GPuser') as GP
from social_user
group by concat(date(added_datetime),MONTH(added_datetime))
编辑:
而不是group by concat(date(added_datetime),MONTH(added_datetime))
您可以使用
group by `Year_month`