Revenue and Headcount Per Department

Return one row per department with:

  • department — the department name
  • headcount — how many employees it has
  • revenue — the total amount of its orders

Every department must appear, including any with no employees or no orders. Report 0 and 0.00 rather than NULL.

Order by department.

A warning. Joining department to both employee and "order" in one FROM clause gives wrong numbers for both columns. Engineering's real revenue is 6000.00; that query reports 18000.00.

Expected output


department  | headcount | revenue
------------+-----------+--------
Engineering | 3         | 6000.00
Research    | 0         | 0.00
Sales       | 1         | 750.00
Support     | 2         | 0.00
PostgreSQL

Press Run to start the SQL engine.

SensAI
Beta
Tap the mic to stop voice mode