开发者

MySql: Grouping a grouped statement possible?

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开发者_JS百科 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


You could use a subquery to group on employeeid:

select employeeid, sum(short)
from (
   <your sql here>
) sub
group by employeeid


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜