按条件count ,一条SQL里面
select eq_no,
count(if(out_in_type = '01',1,null)) as inCount, //01 进场人次
count(if(out_in_type = '02',1,null)) as OutCount, //02 出场人次
ent_name,
ent_id,
COUNT(DISTINCT id_card_no, if(out_in_type = '01',1,null)) as inCountPeople, // 按身份证号去重后的进场人数
COUNT(DISTINCT id_card_no, if(out_in_type = '02',1,null)) as OutCountPeople,
out_in_type
from t_tm_eq_scan_record
group by eq_no
但是最好别这么干,效率很低。 统计行数最好单独做个表,在条件查询影响不大的情况下
下班记得打卡

浙公网安备 33010602011771号