【发布时间】:2021-01-11 22:02:41
【问题描述】:
这是我的查询
Select max(sale) as MaximumSales, cID
From(
Select SUM(totalPerSale) as sale,CustomerID as cID
From(
Select Quantity, UnitPrice,
Quantity*UnitPrice as totalPerSale, CustomerID
From DbAssignment.`e-commerce-2021 (1)` order by totalPerSale DESC
) as Records
group by CustomerID order by CustomerID DESC)
as total
我想做的是让花最多钱的客户.... 具有别名 Records 的内部子查询按预期工作。它返回每个客户花费的金额总和。但是最外层的查询别名总计没有给出正确的 CustomerID 当我将它与最外层的选择一起使用时,它会返回数据集中的第一个 CustomerID...虽然 MAX 正在返回正确的数据....
我该如何解决...
还有其他方法吗?
【问题讨论】: