显示 2010 年销售手机但 2009 年没有销售手机的制造商。(USING MYSQL)

Show the manufacturers that sold cellphone in 2010 but didn’t in 2009. (USING MYSQL)

SELECT Manufacturer_Name
FROM DIM_MANUFACTURER
     INNER JOIN DIM_MODEL ON DIM_MANUFACTURER.IDManufacturer = DIM_MODEL.IDManufacturer
    WHERE DIM_MANUFACTURER.IDManufacturer IN
          (
          SELECT DIM_MODEL.IDManufacturer
            FROM DIM_MODEL
            INNER JOIN FACT_TRANSACTIONS ON DIM_MODEL.IDModel = FACT_TRANSACTIONS.IDModel
             WHERE DIM_MODEL.IDMODEL IN 
             (
             SELECT FACT_TRANSACTIONS.IDModel
              FROM FACT_TRANSACTIONS
             WHERE IDModel NOT IN (YEAR(STR_TO_DATE(Date_d,'%m/%d/%Y')) = 2009) AND 
                IDModel In (YEAR(STR_TO_DATE(Date_d,'%m/%d/%Y')) = 2010)));

嗯。 . .我在想 existsnot exists:

select m.*
from dim_manufacturer m
where exists (select 1
              from transactions t join
                   dim_models mo
                   using (idmodel)
              where m.IDManufacturer = mo.IDManufacturer and
                    t.date_d >= '2010-01-01' and t.date_d < '2011-01-01'
             ) and
      not exists (select 1
                  from transactions t join
                       dim_models mo
                       using (idmodel)
                  where m.IDManufacturer = mo.IDManufacturer and
                        t.date_d >= '2009-01-01' and t.date_d < '2010-01-01'
                 ) ;