Question
Consider a table Orders with columns OrderID,
CustomerID, OrderDate, and TotalAmount. Which SQL query would correctly find the total number of orders and the average TotalAmount for each CustomerID who has placed more than 5 orders? Option A) SELECT CustomerID, COUNT(OrderID), AVG(TotalAmount) FROM Orders GROUP BY CustomerID WHERE COUNT(OrderID) > 5; Option B) SELECT CustomerID, COUNT(OrderID), AVG(TotalAmount) FROM Orders WHERE COUNT(OrderID) > 5 GROUP BY CustomerID; Option C) SELECT CustomerID, COUNT(OrderID), AVG(TotalAmount) FROM Orders GROUP BY CustomerID HAVING COUNT(OrderID) > 5; Option D) SELECT CustomerID, COUNT(OrderID), AVG(TotalAmount) FROM Orders HAVING COUNT(OrderID) > 5 GROUP BY CustomerID; Option E) None of the aboveSolution
SELECT CustomerID, COUNT(OrderID), AVG(TotalAmount) FROM Orders GROUP BY CustomerID HAVING COUNT(OrderID) > 5;Â Explanation: The WHERE clause is used to filter individual rows *before* grouping, and it cannot contain aggregate functions. The HAVING clause is used to filter groups *after* the GROUP BY clause has been applied, and it can use aggregate functions. The correct order of execution in a SELECT statement is FROM, JOIN, WHERE, GROUP BY, HAVING, SELECT, ORDER BY. Therefore, to filter groups based on an aggregate condition (COUNT(OrderID) > 5), the HAVING clause must be used after GROUP BY.Â
Bank credit to NBFCs (MFI) and other recognized MFIs by RBI, for on-lending will be allowed up to what limit of an individual bank’s total priorit...
What percentage of their total outstanding advances, are RRBs to lend to the sectors eligible for classification as priority sector lending and sub sect...
Which of the following completes the loop of this process?
In case of a defined benefit pension plan, the risk of investment and planning is with _____
______ is a 20 character global reference number conceived by G20 that uniquely identifies every entity or structure that is party to a financ...
Which section of SARFAESI Act deals with measures of Asset Reconstruction?
What was the increase in India’s net Foreign Portfolio Investment (FPI) flows in FY24, the highest since FY15 as per the economic survey 2023-24?
Cost of capital is lowest in case of debt due to which of the following:
Accounts relating to income, revenue, gain expenses, and losses are termed as:
As of FY24, which Indian bank reported the lowest net Non-Performing Assets (NPAs)?