sql 中多条件使用-if

SELECT date_str, count(distinct if(new_id=1, device_id, null)) AS new_uv,round(count(distinct if(new_id=1, device_id, null))/count(distinct device_id)*100,0) AS new_uv_ratio,count(distinct device_id) AS uv FROM mdata_flows_user_realtime_all WHERE source IN ('1','2','3','4') AND hour_str IN ('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15') AND date_str IN ('2021-05-25','2021-05-24','2020-05-25','2021-05-18') GROUP BY date_str

你可能感兴趣的:(sql 中多条件使用-if)