views:

73

answers:

2

Hi,

I have a SQL Statement with some joins and grouping applied. I also have a Count() column. This is what the resulting data looks like:

+----------------+-----------------+----------------+
|   EMPLOYEEID   |     REQTYPE     |  SHORT (count) |
+----------------+-----------------+----------------+
|       1        |        5        |       0        |
+----------------+-----------------+----------------+
|       2        |        5        |       0        |
+----------------+-----------------+----------------+
|       2        |        7        |       1        |
+----------------+-----------------+----------------+

I want to group (again) by EmployeeId (the query above is already grouped by EmployeeId once). Is this possible in the same query, or should I use a subquery?

Update: I want to remove the REQTYPE and have a SUM of SHORT for EMPLOYEEID

+3  A: 

You could use a subquery to group on employeeid:

select employeeid, sum(short)
from (
   <your sql here>
) sub
group by employeeid
Andomar
I already expected this. Thanks
Ropstah
A: 

Your question makes no sense to me, even after our discussion in the comments. However, you can just query the results of the query you already have:

  SELECT s.EMPLOYEEID, SUM(s.SHORT) AS SHORTSUM FROM
  (Your original grouping query here) s
  GROUP BY s.EMPLOYEEID
Ken White