SELECT pj.type AS type, count( pj.id ) AS project_count, count( evt.id ) AS alarm_count, ( SELECT count(id) from t_device where type=1) as camera_count, ( SELECT count(id) from t_device where type=2) as ai_box_count, ( SELECT count(id) from t_device where type=3) as radar_count, ( SELECT count(id) from t_device where type=4) as sensor_count, ( SELECT count(evt.id) FROM t_probably where project=pj.id AND status <> 1 and status is not null ORDER BY alarm_time DESC LIMIT 1 ) AS dissipate_event FROM t_project AS pj LEFT JOIN t_device AS dev ON pj.id = dev.project LEFT JOIN t_probably AS evt ON pj.id = evt.project LEFT JOIN t_organize AS org ON pj.organize = org.id ORDER BY pj.type DESC 在这段sql中,为什么project_count的数据和表里数据数量不一致
时间: 2023-06-13 17:08:34 浏览: 81
sll.zip_isr_evt_set原理_sll
可能是因为在 JOIN 表时,有些项目(t_project)没有对应的设备(t_device)或报警(t_probably),这些项目在统计 project_count 时会被算作 0,导致最终的 project_count 数量和表中的数据数量不一致。另外,如果在 t_project 表中有重复的 id,也会导致最终的统计结果与表中的数据数量不一致。
阅读全文