Mysql 组_CONCAT行if值
我需要计算表中的记录,但我必须将pId为55和61的值视为一个,前提是用户id相同Mysql 组_CONCAT行if值,mysql,group-concat,Mysql,Group Concat,我需要计算表中的记录,但我必须将pId为55和61的值视为一个,前提是用户id相同 id pId user_id 6126 55 127742 6128 55 127584 6132 58 128788 6134 55 54445 6136 55 127897 6139 61 127584 select id, pId, user_id, count(1), from table where date >=
id pId user_id
6126 55 127742
6128 55 127584
6132 58 128788
6134 55 54445
6136 55 127897
6139 61 127584
select id, pId, user_id, count(1),
from table
where date >= '2017-01-19 00:00:00' AND date < '2017-01-20 00:00:00'
group by user_id
;
创建另一个表,其中61替换为55。现在计算你想计算的任何东西
select a.user_id, count(distinct a.pid_user_id)
from (select id,
concat(if(pid = 61, 55, pid) , '_', user_id) as pid_user_id,
user_id
from table
where date >= '2017-01-19 00:00:00' AND date < '2017-01-20 00:00:00') as a
group by a.user_id;
我不太明白。从您的样本数据来看,最终结果应该是什么?你的要求和团体有什么关系?我想数一数。最终结果应该是9行而不是10行,因为id为6128的行与第6139行具有相同的用户id,并且PID是55和61。当存在相同的用户id时,我只需将55和61组合在一起。已编辑的示例数据。请参阅