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

MySQL krydstabel / pivot-aggregation. Fjernelse af tællinger baseret på kolonne i anden tabel

SELECT
    CASE
        WHEN ci.make_model LIKE "Acura%" THEN "Acura"
        WHEN ci.make_model LIKE "Ford%" THEN "Ford"
        WHEN ci.make_model LIKE "Toyota%" THEN "Toyota"
        WHEN ci.make_model LIKE "Tesla%" THEN "Tesla"
    END AS Make,
    SUM(CASE WHEN ci.color = "Black" THEN 1 ELSE 0 END) as Black,
    SUM(CASE WHEN ci.color = "Blue" THEN 1 ELSE 0 END) as Blue,
    SUM(CASE WHEN ci.color = "White" THEN 1 ELSE 0 END) as White
FROM car_inventory ci
WHERE 
    (ci.year > 2012) and
    (ci.car_id not in (select distinct il.car_id from inventory_log il where il.note like '%issue%'))
GROUP BY Make
ORDER BY Make;


  1. JAVA MySQL Connection ClassNotFound undtagelse

  2. XMLType i oracle genererer ikke tags for kolonner med Null-værdier

  3. Sådan opdateres forbundne tabeller i Access 2016, efter at backend-databasen er flyttet til en ny placering

  4. Advarsel:mysqli_connect():Ukendt MySQL-servervært