I have this data in table 1ID VRef Type CAPID Make Model Derivative110 12594 Car 37863 TOYOTA VERSO DIESEL ESTATE 2.2 D-4D T Spirit 5dr111 12595 Car 37860 TOYOTA VERSO DIESEL ESTATE 2.2 D-4D T2 5dr112 12596 Car 37862 TOYOTA VERSO DIESEL ESTATE 2.2 D-4D T3 5dr
Table 2 contains a collection of figures associated with each VRefID VRef Term Miles Maint Price114851 12594 2 10000 False 248.9900114852 12594 2 10000 True 275.9900114853 12594 2 20000 False 280.9900114854 12594 2 20000 True 324.9900114855 12594 2 30000 False 312.9900114856 12594 2 30000 True 373.9900114857 12594 3 10000 False 229.9900114858 12594 3 10000 True 256.9900114859 12594 3 20000 False 254.9900114860 12594 3 20000 True 305.9900114861 12594 3 30000 False 278.9900114862 12594 3 30000 True 354.9900114863 12595 2 10000 False 193.9900114864 12595 2 10000 True 220.9900114865 12595 2 20000 False 221.9900114866 12595 2 20000 True 265.9900114867 12595 2 30000 False 248.9900114868 12595 2 30000 True 310.9900114869 12595 3 10000 False 183.9900114870 12595 3 10000 True 210.9900114871 12595 3 20000 False 204.9900114872 12595 3 20000 True 256.9900114873 12595 3 30000 False 225.9900114874 12595 3 30000 True 301.9900114875 12596 2 10000 False 222.9900114876 12596 2 10000 True 249.9900114877 12596 2 20000 False 252.9900114878 12596 2 20000 True 296.9900114879 12596 2 30000 False 281.9900114880 12596 2 30000 True 342.9900114881 12596 3 10000 False 207.9900114882 12596 3 10000 True 234.9900114883 12596 3 20000 False 230.9900114884 12596 3 20000 True 282.9900114885 12596 3 30000 False 252.9900114886 12596 3 30000 True 329.9900
My view needs to group the vehicles by derivative add in in the cheapest 2 year and three year prices.I have this view, which I thought was working until today (theres columns in the view omitted from the above tables for clarity.SELECT TOP (100) PERCENT Manufacturer, Model, MIN(Derivative) AS Expr1, MIN(LOCatCode) AS Expr2, MIN(TwoYearPrice) AS TwoYearPrice, MIN(ThreeYearPrice) AS ThreeYearPriceFROM (SELECT TOP (100) PERCENT A.Manufacturer, A.Model, A.Derivative, A.LOCatCode, B.CH AS TwoYearPrice, C.CH AS ThreeYearPrice FROM dbo.tblNewMatrixLtd AS A INNER JOIN dbo.tblNewMatrixFigures AS B ON A.VehicleRef = B.VehicleRef AND B.Term = 2 AND B.MilesPA = 10000 AND B.Maintained = 0 INNER JOIN dbo.tblNewMatrixFigures AS C ON A.VehicleRef = C.VehicleRef AND C.Term = 3 AND C.MilesPA = 10000 AND C.Maintained = 0 WHERE (A.eMatrixLive = 1) AND (A.Authorized = 1) ORDER BY A.Manufacturer, A.Model) AS derivedtbl_1GROUP BY Manufacturer, ModelORDER BY Manufacturer, Model
In the above example the following data is returned.TOYOTA VERSO DIESEL ESTATE 2.2 D-4D T Spirit 5dr 3 193.9900 183.9900BUTThe cheapest VERSO DIESEL ESTATE should be the D-4D T2 5dr - the prices it has returned are correct, just not the derivative.Thanks