按条件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