select project_no, sum(case when device_state=0 then 1 else 0 end)as offTotal , sum(case when device_state=1 then 1 else 0 end)as onlineTotal, sum(1)total from iot_d_device group by project_no order by project_no
select project_no, sum(case when device_state=0 then 1 else 0 end)as offTotal , sum(case when device_state=1 then 1 else 0 end)as onlineTotal, sum(1)total from iot_d_device group by project_no order by project_no