How to find a company with max sum of orders during a period? Not max single order but a sum of orders during any period i want? I need to return CustAccount
I've tried something like that but it doesn't work
SELECT ct."CustAccount", max(m)
FROM "CustTrans" as ct
group by "CustAccount", "Amount"
order by "Amount" desc
(select sum(ct."Amount"))
from "CustTrans" as ct
WHERE ct."TransDate" BETWEEN '01/01/2000' and '31/01/2022')) as m
CodePudding user response:
I think something like
SELECT MAX(CustAccount), FROM CustTrans Where TransDate BETWEEN '01/01/2000' and '31/01/2022' ORDER BY TransDate ASC