这是我的输入表(选项卡),其中包含用户 ID 和“已验证购买”。 (用户可以尝试购买,但可能决定不购买。因此已验证购买)
UserID Verified_Purchase
1001 T
1001 T
1001 F
1002 T
1002 T
1003 F
1004 T
1004 F
My expected output is to find out the no of unique buyers / non buyers.
No of Buyers : 3 (1001,1002,1004)
No of Non Buyers : 1 (only 1003)
我尝试过:
select distinct UserID from tab
WHERE Verified_Purchase = 'T'
select distinct UserID from tab
WHERE Verified_Purchase = 'F'
但是这些并没有给出正确的答案,因为很少有用户被重复计算。
请告诉我如何继续进行同样的操作。
最佳答案
首先按userId汇总,然后聚合:
select is_verified, count(*) as num_users
from (select UserId, max( Verified_Purchase = 'T' ) as is_verified
from tab t
group by UserId
) t
group by is_verified;
关于mysql - 统计付费用户的不同数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48614284/