Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Invertiertes SQL SELECT – Finden Sie Mitarbeiter, die zwischen einem Datumsbereich keine Kaltakquise getätigt haben

Verwenden Sie LEFT JOIN

SELECT  a.name
FROM    staff a
        INNER JOIN staff_prospects b
            ON b.staff_id = a.id
        LEFT JOIN staff_prospect_activity c
            ON  c.prospect_id = b.id AND
                c.date_of_activity >= '2013-05-31' AND 
                c.date_of_activity < '2013-05-31' + INTERVAL 1 DAY
WHERE   c.prospect_id IS NULL
GROUP   BY a.name