Re: SQL query question

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL query question
Date: 2007-10-07 19:16:16
Message-ID: 1191784576.250021.263080@50g2000hsm.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sep 21, 12:09 am, stevenleong(dot)(dot)(dot)(at)gmail(dot)com wrote:
> Write the query (or queries if necessary) needed to count the number
> of employees in each employee's department who are paid more than
> their manager.

SELECT e.dept, COALESCE (SUM (1), 0) AS n
FROM employees e JOIN employees m
ON (e.empid = m.mgrid AND e.salary > m.salary)
GROUP BY e.dept
ORDER BY e.dept

Browse pgsql-sql by date

  From Date Subject
Next Message Dani Castaños 2007-10-08 10:49:04 Get different sums from the same table in one query
Previous Message Shane Ambler 2007-10-06 00:50:00 Re: [SQL] Why does the sequence skip a number with generate_series?