SELECT C.CarID, C.Make, Y.Year, M.Model , e.Engine
FROM Car C
INNER JOIN CarYear CY ON CY.CarID = C.CarID
INNER JOIN Year y ON y.YearID = CY.YearID
INNER JOIN Model m ON m.CarID = C.CarID
INNER JOIN Engine e ON e.ModelId = m.ModelID
我是 SQL SERVER 的新手,请告诉我如何解决这个问题。我将所有表格分开,汽车、年份、型号、引擎。我用交叉连接填充桥表 dbo.CarYear & dbo.ModelYear,现在我有这个查询,结果是:
1 Acura 1999 ILX 1.5 L LR ELECT/GAS
1 Acura 1999 ILX 2.0 L L4 SOHC
1 Acura 1999 ILX 2.4 L L4 DOHC
1 Acura 1999 RDX 3.5 L V6
1 Acura 1999 RLX 3.5 L V6
1 Acura 1999 MDX 3.7 L V6
1 Acura 2000 ILX 1.5 L LR ELECT/GAS
1 Acura 2000 ILX 2.0 L L4 SOHC
1 Acura 2000 ILX 2.4 L L4 DOHC
1 Acura 2000 RDX 3.5 L V6
1 Acura 2000 RLX 3.5 L V6
1 Acura 2000 MDX 3.7 L V6
1 Acura 2001 ILX 1.5 L LR ELECT/GAS
1 Acura 2001 ILX 2.0 L L4 SOHC
1 Acura 2001 ILX 2.4 L L4 DOHC
1 Acura 2001 RDX 3.5 L V6
1 Acura 2001 RLX 3.5 L V6
1 Acura 2001 MDX 3.7 L V6
1 Acura 2002 ILX 1.5 L LR ELECT/GAS
1 Acura 2002 ILX 2.0 L L4 SOHC
1 Acura 2002 ILX 2.4 L L4 DOHC
1 Acura 2002 RDX 3.5 L V6
1 Acura 2002 RLX 3.5 L V6
1 Acura 2002 MDX 3.7 L V6
1 Acura 2003 ILX 1.5 L LR ELECT/GAS
1 Acura 2012 ILX 1.5 L LR ELECT/GAS
1 Acura 2012 ILX 2.0 L L4 SOHC
1 Acura 2012 ILX 2.4 L L4 DOHC
1 Acura 2012 RDX 3.5 L V6
1 Acura 2012 RLX 3.5 L V6
1 Acura 2012 MDX 3.7 L V6
1 Acura 2013 ILX 1.5 L LR ELECT/GAS
1 Acura 2013 ILX 2.0 L L4 SOHC
1 Acura 2013 ILX 2.4 L L4 DOHC
1 Acura 2013 RDX 3.5 L V6
1 Acura 2013 RLX 3.5 L V6
1 Acura 2013 MDX 3.7 L V6
如您所见,任何年份的所有讴歌都有相同的型号,例如,我如何在填充桥牌表之前消除一些汽车型号,(例如,讴歌 ILX 仅从 2013 年开始)