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