私は、次の表があります。このクエリを実行する他の方法はありますか?
Animals (animal_id, producer_id, ...)
Producers (prod_id, ...)
BoughtAnimals (animal_id (fk), ...)
をし、私はそれが持っているどのように多くの動物、各プロデューサーのために私に語った問い合わせをしたいのですが、どのように多くのそれらの動物のを買いました。
select Producers.name, count (distinct A1.animal_id), count(distinct BoughtAnimals.animal_id)
from Producers, Animals A1, Animals A2, BoughtAnimals
where
Producers.nif = A1.producer_id and
Producers.nif = A2.producer_id and
BoughtAnimals.animal_id = A2.animal_id
group by Producers.name;
が、私は唯一の試行錯誤によってそれをやった、と私はそれは難しい、一度に複数の動物のテーブルについて推論するために見つける:あまり考えた後、私は次のようなアプローチを試してみました。このクエリを作成する他の方法はありますか?それともこれが通常のやり方ですか?
暗黙の構文の使用をやめ、結合について学ぶと、より良いクエリの実行方法を理解できます。 – HLGEM