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

mysql:rimuove le righe con valori ripetuti con condizione (colonne ripetute)

Dovresti cercare questo:

Qui stiamo omettendo i key record values (date + name) quelli corrispondono in un'intersezione di key record values (date + name) who played football e 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;