如果MySql具有不同的

如果MySql具有不同的,mysql,sql,Mysql,Sql,请帮我查询,我有这些数据 customeid | param 1001 | A 1001 | B 1001 | C 1002 | B 1002 | A 1003 | A 1003 | B 1004 | A 我需要区分customeid,我使用此查询,但结果不正确 SELECT COUNT(DISTINCT IF(param not in ('A'),1,0)) FROM table 输出结

请帮我查询,我有这些数据

customeid | param
1001      |  A
1001      |  B
1001      |  C
1002      |  B
1002      |  A
1003      |  A
1003      |  B
1004      |  A
我需要区分customeid,我使用此查询,但结果不正确

SELECT
  COUNT(DISTINCT IF(param not in ('A'),1,0))
FROM
  table
输出结果

count   
  3 (from customeid 1001,1002,1003)
如何区分customeid和if参数不在A中,并且我不能添加where查询时的用例和聚合函数分组依据

使用count if with distinct判断没有问题,但存在问题,如果满足条件,则需要返回customeid,否则需要返回null

您可以按照此查询进行操作

SELECT
  COUNT(DISTINCT IF(param not in ('A'),customeid,NULL))
FROM
  table


当该值为空时,计数不会累积

输出表将帮助预期输出为3?是,我想对customeid distinct进行计数,其中参数!=A但我不能使用where查询,因为这只是我的select查询的一部分。如果我是对的,您的表的计数必须是3?@Denny R.z有用吗?没问题:,很乐意帮助
select customeid,count(customeid)
from table
where param <>'A'
group by customeid
SELECT
  COUNT(DISTINCT IF(param not in ('A'),customeid,NULL))
FROM
  table
SELECT DISTINCT COSTUMEID, COUNT(DISTINCT (PARAM))
FROM TABLE 
WHERE PARAM NOT IN (('A'),1,0) 
GROUP BY COSTUMEID