Ok the question is that Im to find the room that has created the most revenue from services. In other words: Which room has accumulated the highest amount of charges for various services.
What Im wondering is if this is an effective way of finding the max in a group. Here's my SQL (This is Oracle btw)
Code:
Select Room_Number, SUM(Charge_For_Service)
From Service_Performed
Group By Room_Number
Having SUM(Charge_For_Service) >= ALL(Select SUM(Charge_For_Service)
From Service_Performed
Group By Room_Number);
It works just fine. It compares the SUM(Charge_For_Service) to itself and finds the MAX basically. I've tried figuring out a way to use the MAX function but you cant do a function on a function unfortunately i.e. MAX(SUM(Charge_For_Service)).
Opinions? Suggestions? Like I said it works which Im happy but I just wanna make things efficient so I can know what to do next time.