Reputation: 145
- Goal: Count the number of suppliers (supplier) and parts (vehicle_part) for each vehicle for which there are two or more suppliers.
- requirements:
Expected columns: vehicle_name, vehicle_part_count, supplier_count
in that order
Upvotes: 0
Views: 1436
Reputation: 1
select v.vehicle_name, count(distinct vp.vehicle_part_id) as
vehicle_part_count, count(distinct vps.supplier_id) as supplier_count
from vehicle_part vp
join vehicle_part_supplier vps on
vp.vehicle_part_id=vps.vehicle_part_id
join vehicle v on vp.vehicle_id = v.vehicle_id
group by v.vehicle_name
having count(distinct vps.supplier_id)>=2;
Upvotes: 0
Reputation: 106
Goal: Count the number of suppliers (supplier) and parts (vehicle_part) for each vehicle for which there are two or more suppliers <-- for each part ?
There could be like 5 parts of a vehicle so 1 supplier per part = 5 different suppliers, does that count or not ?
Upvotes: 1