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;
在实践中,查询运行良好,但我必须使用子查询,它必须给出有序结果,并且在我看来,如果有两个客户订购了相同类型的相同数量的件,则它不起作用。 谁能告诉我如何解决这个问题。我尝试使用 where Total = (select 但它给了我一个错误
选择产品线、客户名称、总和(总计)
来自( 从客户、订单、产品线、产品、订单详细信息中选择productLines.productline、customers.customerName、sum(quantityOrdered) 作为总计,其中customers.customerNumber =orders.customerNumber 和orderdetails.orderNumber=orders.orderNumber 和orderdetails.productCode = products.productCode 和Productlines.productLine= products.productLine GROUP(按产品线、客户名称)作为列表
其中总计 = ( 从中选择最大值(totale1) ( 从客户、订单、产品线、产品、订单详细信息中选择productLines.productline、customers.customerName、sum(quantityOrdered) as totale1,其中customers.customerNumber =orders.customerNumber和orderdetails.orderNumber=orders.orderNumber和orderdetails.productCode = products.productCode和产品线.productLine= 产品.productLine 按产品线、客户名称分组 ) 作为 x
)
按产品线分组;
向前迈出一步... 想法???