HomeInterview QuestionsList the top 3 departments by revenue.

List the top 3 departments by revenue.

🟡 Medium Coding Junior level
1Times asked
May 2026Last seen
May 2026First seen

💡 Model Answer

To find the top three departments by revenue, join the visits and billing tables on visit_id, aggregate the amount per department, order by the sum descending, and limit the result to three rows. Example:

SELECT v.department,

   SUM(b.amount) AS revenue

FROM visits v

JOIN billing b ON v.visit_id = b.visit_id

GROUP BY v.department

ORDER BY revenue DESC

LIMIT 3;

This query returns each department name and its total revenue, sorted from highest to lowest, showing only the top three.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500