提供靠近解题的都会采纳急!!
需求:用户看了视频就是item_Id,有对应的is_rh,需要统计用户查看的is_rh的值如果全是1,是就统计加1,如果是0也统计,如果存在0或者1的也统计
可以用sql查询,也可以查出来用java代码实现

提供靠近解题的都会采纳急!!
需求:用户看了视频就是item_Id,有对应的is_rh,需要统计用户查看的is_rh的值如果全是1,是就统计加1,如果是0也统计,如果存在0或者1的也统计
可以用sql查询,也可以查出来用java代码实现

以user_id统计每个用户is_rh为1、0的情况如下:
select
user_id,
sum(case when is_rh=1 then 1 else 0 end) '为1总数',
sum(case when is_rh=0 then 1 else 0 end) '为0总数'
from 表名
group by user_id
统计所有user_id中全为1、全为0、存在0或1的情况如下:
select sum(case when con1>0 and con0=0 then 1 else 0 end) '全为1',
sum(case when con1=0 and con0>0 then 1 else 0 end) '全为0',
sum(case when con1>0 and con0>0 then 1 else 0 end) '存在1和0'
(
select
user_id,
sum(case when is_rh=1 then 1 else 0 end) con1,
sum(case when is_rh=0 then 1 else 0 end) con0
from 表名
group by user_id
) item
