is’t right in classic models find customers that have orderd most. I don’t find customers that have ordered the same quantity

  Kiến thức lập trình

select productline, customerName, totale from
(SELECT productLines.productline, customers.customerName, sum(quantityOrdered) as totale
from customers, orders, productlines, products, orderdetails
WHERE customers.customerNumber = orders.customerNumber
and orderdetails.orderNumber= orders.orderNumber
and orderdetails.productCode = products.productCode
and productlines.productLine= products.productLine
GROUP by productlines.productline, customers.customerName
order by sum(quantityOrdered) desc )
as lista
group by productline;

in practice the query works well but I had to use a subquery which must give ordered results and in my opinion it doesn’t work if there are two customers who have ordered the same number of pieces for the same type.
Can anyone tell me how to solve this problem. I tried with where total = (select but it gives me an error

New contributor

user17572394 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT