Question
Which SQL query would return the top three departments
with the highest total salaries from an employees table with columns department , salary , and employee_id ?Solution
Explanation: The correct query uses SQL’s GROUP BY to aggregate data by department , calculates the sum of salary for each department using SUM(salary) , and orders the results in descending order with ORDER BY . Finally, the LIMIT 3 clause retrieves only the top three departments. This approach is efficient and aligns with database query standards, ensuring the highest salaries are calculated accurately and in rank order. Option B: MAX(salary) cannot be used without a GROUP BY clause for the entire table, and the syntax is incorrect. Option C: COUNT(salary) measures frequency, not total salary. Option D: DISTINCT eliminates duplicates but does not aggregate data for rankings. Option E: MAX(salary) sorts by individual highest salaries, not aggregated totals, leading to incorrect results.
Harvey, Mike, and Donna started a business together, with the ratio of Harvey's investment to Mike's being 5: x, and the ratio of Mike's investment to D...
In a business, A invested Rs. 1500 more than that by B. After 10 months, A left the business. If at the end of the year, profit earned by B is equal to ...
Pragya and Pankaj started a business investing Rs.70, 000 and Rs. 30,000 respectively. In what ratio the profit earned after 2 years be divided?
X, Y, and Z invested ₹1,20,000, ₹1,50,000, and ₹1,80,000, respectively, in a partnership business. The annual profit was ₹1,50,000. If X withdre...
A and B started a business by investing Rs.450 and Rs.600 respectively. After 8 months, A increased his investment by Rs.850. Find the ratio of annual p...
Sohan starts a business with an initial investment of Rs. 20,000. After 5 months, Rohan joins the business by investing Rs. 5,000 more than Sohan. After...
‘M’ started a business with an investment of Rs. 2700. After 3 months ‘N’ joins the business with an investment of Rs. 2200. If the total profit...
‘A’ and ‘B’ started a business by investing Rs. 12000 and Rs. 18000, respectively. 6 months later, ‘C’ joined them with an investment equal ...
A and B started a retail store with initial investments in the ratio 6:7 and their annual profits were in the ratio 3:4. If A invested the money for 7 m...
Rohan and Deepak invested Rs. 10,000 and Rs. 15,000 respectively. After 3 months, Rohan reduced his investment by Rs. 2,000 and Aman joined with Rs. 20,...