My homework is based on sql tables i created revolving around a vehicle
My homework is based on sql tables i created revolving around a vehicle
sales database. It requires i build a SELECT query to display the institution and loan type of the financing plan that was used for the most sales. I have found other solutions online (which i have pasted below), and while it makes sense in my head, It keeps displaying all the institutions and loan types. I cannot get the Rank to work correctly to only show the top results. I need help with the correct format of Rank or some help on what i am doing wrong. Thanks
select institution, loan_type
from financing_plans
where plan_id=(select financing_plans.plan_id
from(select sales_financings.plan_id,
Count(*) as plan_count,
Rank () over (order by count (*) desc)
as Rank
from sales
inner join SALES_FINANCINGS
on sales.sale_id = sales_financings.sale_id
group by sales_financings.plan_id)
where rank=1);