-1

我的数据表如下:

ID WEEK   RESULT 
1   13     GOOD
2   13     BAD
3   13     GOOD
4   13     WORST
5   14     GOOD
6   14     BAD
7   14     WORST
8   15     BAD
9   15     WORST

我需要一个 sql 查询来创建一个数组,如下所示:

WWEK   GOOD_RESULT   BAD_RESULT   WORST_RESULT   TOTAL
13            2             1       1              4
14            1             1       1              3
15            0             1       1              2

谁能帮我找到合适的mysql查询?

4

1 回答 1

0
SELECT
  WEEK,
  SUM(RESULT='GOOD') As GOOD_RESULT,
  SUM(RESULT='BAD') As BAD_RESULT,
  SUM(RESULT='WORST') AS WORST_RESULT,
  COUNT(*) As TOTAL
FROM YourTable
GROUP BY
  WEEK

在此处查看小提琴。

于 2013-05-03T19:57:17.780 回答