X = Y组的情况如何用Y求和?

问题描述 投票:-1回答:1

我正在尝试编写一个查询,说明iff在all1o1sSC.salesforce_id中存在ID,然后将它存在于all1o1s中的次数求和。

我写:

select 
   sc.salesforce_id,
   sum(case when all1o1s.member_id = sc.salesforce_id then 1 else 0) as "1o1 completed count"
from salesforce_contacts as sc 
inner join leenk_1o1s as all1o1s on sc.salesforce_id = all1o1s.member_id    
group by sc.salesforce_id;

我在总和线上得到一个错误。如何构建此查询?

谢谢!

mysql sum case-when
1个回答
0
投票

试试这个

 select b.salesforce_id,count(1) from all1o1s a,salesforce_contacts b where a.id=b.salesforce_id
group by b.salesforce_id having count(1) > 1

根据你的问题,你需要数不算

© www.soinside.com 2019 - 2024. All rights reserved.