sql >> Database teknologi >  >> RDS >> Mysql

Får ikke korrekt COUNT() i MySQL-forespørgsel (modificeret tidligere)

Prøv dette:

SELECT 
    sch.id,
    SUM(IF(app.status = 'completed' , 1, 0)) 
FROM 
    com_event_schedules sch
INNER JOIN  com_event_schedules_com_appointment_c rel 
    ON rel.com_event_schedules_com_appointmentcom_event_schedules_ida = sch.id 
INNER JOIN com_appointment app
    ON rel.com_event_schedules_com_appointmentcom_appointment_idb = app.id 
GROUP BY
    sch.id
HAVING
    COUNT(*) > 1


  1. ClusterControl:Introduktion til New Query Monitor

  2. mysql_connect VS mysql_pconnect

  3. Såning af en MySQL DB til en dockeriseret Django-app

  4. Er min IP i min database, så find tidsstempel