我使用了以下查询
SELECT COUNT(client_mac) AS total_users
FROM `social_user`
WHERE social_network ='TWuser'
GROUP BY client_mac HAVING total_users > 1
运行此查询后,我得到了这个结果
Please click here to see my result
但我需要理解我的' total_users'列,所以我的输出应该是
total_users: **49**
对不起我的英语,我没有足够的声誉来附上图片,这就是我添加链接的原因
答案 0 :(得分:1)
我认为这可能会对你有所帮助
select count(client_mac) as total_user,client_mac
from social_user
where social_network = 'TWuser'
GROUP BY client_mac`
此查询将为每个用户带来总数而不是所有用户。小提琴是here
答案 1 :(得分:1)
我想我终于明白了你的目标。
SELECT social_network, count(*) as total_users
FROM social_user
INNER JOIN (
SELECT client_mac FROM social_user
GROUP BY client_mac HAVING count(*) > 1
) as src ON src.client_mac = social_user.client_mac
GROUP BY social_network
因此,子查询应该获取所有重复的client_macs,然后查询将按社交网络组织每个条目。
我预见的问题是,如果一个client_mac存在多个社交网络。
答案 2 :(得分:0)
尝试此查询 -
SELECT SUM(total_users) as total_usr_sum from (SELECT COUNT(client_mac) AS total_users FROM `social_user` WHERE social_network ='TWuser' GROUP BY client_mac HAVING total_users > 1) as sum
答案 3 :(得分:0)
只需在查询中将COUNT(client_mac)
替换为SUM(total_users)