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 08:07:59 浏览: 245
根据这段 SQL 语句,project_count 是通过对 t_project 表进行计数得出的,而 t_project 表可能存在重复的记录,因此 project_count 的数据可能比表里实际数据多几条。如果想要避免这种情况,可以在计数时使用 DISTINCT 关键字来排除重复的记录,例如:count( DISTINCT pj.id )。
相关问题
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的数据和表里数据数量不一致
可能是因为在 JOIN 表时,有些项目(t_project)没有对应的设备(t_device)或报警(t_probably),这些项目在统计 project_count 时会被算作 0,导致最终的 project_count 数量和表中的数据数量不一致。另外,如果在 t_project 表中有重复的 id,也会导致最终的统计结果与表中的数据数量不一致。
“self.m_button1.Bind(wx.EVT_BUTTON, MyDialog11(None).OnClick) self.m_button2.Bind(wx.EVT_BUTTON, MyDialog12(None).OnClick) self.m_button3.Bind(wx.EVT_BUTTON, MyDialog13(None).OnClick) self.m_button4.Bind(wx.EVT_BUTTON, MyDialog21(None).OnClick) self.m_button5.Bind(wx.EVT_BUTTON, MyDialog22(None).OnClick) self.m_button6.Bind(wx.EVT_BUTTON, MyDialog23(None).OnClick) self.m_button7.Bind(wx.EVT_BUTTON, MyDialog31(None).OnClick) self.m_button8.Bind(wx.EVT_BUTTON, MyDialog32(None).OnClick) self.m_button9.Bind(wx.EVT_BUTTON, MyDialog33(None).OnClick) self.m_button10.Bind(wx.EVT_BUTTON, MyDialog41(None).OnClick) self.m_button11.Bind(wx.EVT_BUTTON, MyDialog42(None).OnClick) self.m_button12.Bind(wx.EVT_BUTTON, MyDialog43(None).OnClick) self.m_button13.Bind(wx.EVT_BUTTON, MyDialog44(None).OnClick) self.m_button14.Bind(wx.EVT_BUTTON, MyDialog51(None).OnClick) self.m_button15.Bind(wx.EVT_BUTTON, MyDialog52(None).OnClick) self.m_button16.Bind(wx.EVT_BUTTON, MyDialog53(None).OnClick)”逐行翻译
这段代码是用来绑定多个按钮的事件处理函数的。具体来说,代码中的每一行都使用了Bind方法将一个按钮的事件(wx.EVT_BUTTON)与一个对应的事件处理函数(MyDialogXX(None).OnClick)进行绑定。其中,MyDialogXX(None)是一个对话框类的实例化对象,XX代表对话框的编号,用于区分不同的对话框;OnClick是对话框类中的一个方法,用于响应按钮的点击事件。整个代码的作用是为多个按钮分别绑定对应的事件处理函数,以实现不同的功能。
阅读全文