以下是我的两个查询,其中仅添加一个左连接结果就会搞砸。第二个查询结果是准确的,但在第一个查询中通过添加一个左连接输出不正确(如您所见,我只添加了一个左连接,但我没有在 where 子句中对该连接进行任何过滤)。请让我知道我该如何解决这个问题?谢谢,
第一个查询:
SELECT Distinct count(event_id) as event_count from events
Left Join events on events.event_id = my_events.i_event_id
Left Join atdees on events.event_id = atdees.fk_event_id
where my_events.v_title != "NULL" and r_present = 1 and resident_id = '208' and event_atd > date_sub(curdate(), interval 37 day) group by event_count order by event_count desc limit 5
结果:
26 | 12 | 11 | 10
第二个查询:
SELECT Distinct count(event_id) as event_count from events
Left Join events on events.event_id = my_events.i_event_id
where my_events.v_title != "NULL" and r_present = 1 and resident_id = '208' and event_atd > date_sub(curdate(), interval 37 day) group by event_count order by event_count desc limit 5
结果:
2 | 1 | 1 | 1