我试图过滤掉 count(device1_id)=0 和 count(device2_id)=0 的结果。然而,我的逻辑似乎不正确。
select customer_id, count(device1_id), count(device2_id)
from Table
Group by customer_id
having count(device1_id) !=0
and count(device2_id) !=0
从我的角度来看,如果您发布一些说明问题的示例数据将会有所帮助。我很难理解你想要做什么,因为
无论如何:如果您想“删除”两个计数均为 0 的行(从结果集中),则意味着这些计数的总和必须为 0 才能删除它们,因此一种选择是使用
having not count(device1_id) + count(device2_id) = 0