SELECT CarMinDate.DriverID, CarMinDate.MinDate, CarMinDate.RegistrationNumber AS Номер_MinDate, CarMinDate.CarBrandName AS Марка_MinDate, CarMaxDate.MaxDate, CarMaxDate.RegistrationNumber AS Номер_MaxDate, CarMaxDate.CarBrandName AS Марка_MaxDate FROM (Drivers INNER JOIN (SELECT MaxDate.DriverID, MaxDate.MaxDate, Cars.RegistrationNumber, CarBrend.CarBrandName FROM (SELECT DriverID, Max(CarList.CarListDate) AS MaxDate FROM CarList GROUP BY CarList.DriverID) as MaxDate INNER JOIN ((CarBrend INNER JOIN Cars ON CarBrend.[CarBrandId] = Cars.[CarBrandId]) INNER JOIN CarList ON Cars.[CarId] = CarList.[CarId]) ON (MaxDate.DriverID = CarList.DriverID) AND (MaxDate.MaxDate = CarList.CarListDate)) as CarMaxDate ON Drivers.[DriverID] = CarMaxDate.[DriverID]) INNER JOIN (SELECT MinDate.DriverID, MinDate.MinDate, Cars.RegistrationNumber, CarBrend.CarBrandName FROM (SELECT DriverID, Min(CarList.CarListDate) AS MinDate FROM CarList GROUP BY CarList.DriverID) as MinDate INNER JOIN ((CarBrend INNER JOIN Cars ON CarBrend.[CarBrandId] = Cars.[CarBrandId]) INNER JOIN CarList ON Cars.[CarId] = CarList.[CarId]) ON (MinDate.DriverID = CarList.DriverID) AND (MinDate.MinDate = CarList.CarListDate)) as CarMinDate ON Drivers.[DriverID] = CarMinDate.[DriverID]
[/vba] Только даты нормальные поставьте, а то у Вас там 13-й месяц везде
В Access этот запрос выглядит как-то так [vba]
Код
SELECT CarMinDate.DriverID, CarMinDate.MinDate, CarMinDate.RegistrationNumber AS Номер_MinDate, CarMinDate.CarBrandName AS Марка_MinDate, CarMaxDate.MaxDate, CarMaxDate.RegistrationNumber AS Номер_MaxDate, CarMaxDate.CarBrandName AS Марка_MaxDate FROM (Drivers INNER JOIN (SELECT MaxDate.DriverID, MaxDate.MaxDate, Cars.RegistrationNumber, CarBrend.CarBrandName FROM (SELECT DriverID, Max(CarList.CarListDate) AS MaxDate FROM CarList GROUP BY CarList.DriverID) as MaxDate INNER JOIN ((CarBrend INNER JOIN Cars ON CarBrend.[CarBrandId] = Cars.[CarBrandId]) INNER JOIN CarList ON Cars.[CarId] = CarList.[CarId]) ON (MaxDate.DriverID = CarList.DriverID) AND (MaxDate.MaxDate = CarList.CarListDate)) as CarMaxDate ON Drivers.[DriverID] = CarMaxDate.[DriverID]) INNER JOIN (SELECT MinDate.DriverID, MinDate.MinDate, Cars.RegistrationNumber, CarBrend.CarBrandName FROM (SELECT DriverID, Min(CarList.CarListDate) AS MinDate FROM CarList GROUP BY CarList.DriverID) as MinDate INNER JOIN ((CarBrend INNER JOIN Cars ON CarBrend.[CarBrandId] = Cars.[CarBrandId]) INNER JOIN CarList ON Cars.[CarId] = CarList.[CarId]) ON (MinDate.DriverID = CarList.DriverID) AND (MinDate.MinDate = CarList.CarListDate)) as CarMinDate ON Drivers.[DriverID] = CarMinDate.[DriverID]
[/vba] Только даты нормальные поставьте, а то у Вас там 13-й месяц везде Pelena
"Черт возьми, Холмс! Но как??!!" Ю-money 41001765434816