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

mysql:Zeilen mit wiederholten Werten mit Bedingung entfernen (wiederholte Spalten)

Sie sollten danach suchen:

Hier lassen wir die key record values (date + name) weg diese stimmen in einer Schnittmenge von key record values (date + name) who played football und key record values (date + name) who did not play football

SELECT 
    p1.*
FROM
    player p1
        LEFT JOIN
    (SELECT 
        pnfb.*
    FROM
        (SELECT 
        date, name
    FROM
        player
    WHERE
        sport <> 'football') pnfb
    JOIN (SELECT 
        date, name
    FROM
        player
    WHERE
        sport = 'football') pfb ON (pnfb.date = pfb.date
        AND pnfb.name = pfb.name)) p2 ON (p1.date = p2.date AND p1.name = p2.name)
WHERE
    p2.date IS NULL;