我需要计算表格中的记录,但只有当pId
相同时,我才必须将值user_id
55和61视为一个。
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
;
答案 0 :(得分:0)
创建另一个表,其中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;