テーブル:
A,B,Animal,Car
属性:
A:LinkingID, AnimalID, CarID
B:LinkingID, AnimalID, CarID
Animal:AnimalID, Name , Breed
Car:CarID, Weight
私が欲しいもの:
次のような As と B を選択してください。
A.LinkingID=B.LinkingID
(Animals with AnimalID same as A.AnimalID).Name = (Animals with AnimalID same as B.AnimalID).Name
(Animals with AnimalID same as A.AnimalID).Breed = (Animals with AnimalID same as B.AnimalID).Breed
(Animals with AnimalID same as A.AnimalID).Color = (Animals with AnimalID same as B.AnimalID).Color
(Cars with CarID same as A.CarID).Weight = (Cars with CarID same as B.CarID).Weight
私が書いたクエリ:
select * from A dzo
inner join B sar
on dzo.LinkingID = sar.LinkingID
inner join Car c1
on c1.CarID = dzo.CarID
inner join Car c2
on c2.Weight = c1.Weight
and c2.CarID = sar.CarID
inner join Animal v1
on v1.AnimalID = dzo.AnimalID
inner join Animal v2
on v2.Name = v1.Name
and v2.Breed = v1.Breed
and v2.AnimalID = sar.AnimalID
;
より効率的なクエリを作成できますか?