-5

こんにちは、私は特定のIDの特定のアイテムを数えようとしています

デシベルの結果

name                      remarks
joseph greggory           On time
joseph greggory           On time
lara joy                  On time
lara joy                  Absent
Mark Joben                On time
Mark Joben                Absent
Isnaira Lyn               Absent
Isnaira Lyn               Absent

結果は

name                  On time         Late       Absent
joseph Greggory         2              0            0
Lara Joy                1              0            1
Mark Joben              1              0            1
Isnaira Lyn             0              0            2

よろしくお願いします

4

3 に答える 3

4
SELECT  name,
        SUM(CASE WHEN remarks = 'On time' THEN 1 ELSE 0 END) `On time`,
        SUM(CASE WHEN remarks = 'Late' THEN 1 ELSE 0 END) `Late`,
        SUM(CASE WHEN remarks = 'Absent' THEN 1 ELSE 0 END) `Absent`  
FROM    TableName
GROUP   BY name
于 2013-02-07T06:03:33.130 に答える
0

あなたはこれを試すことができます、

select name,
       count(case when remarks = 'On time' then 1 end) "On time",
       count(case when remarks = 'Late' then 1 end) "Remarks",
       count(case when remarks = 'Absent' then 1 end) "Absent"
from table1
group by name;

SQL フィドル出力

于 2013-02-07T06:13:20.913 に答える
0

これを試すことができます:

SELECT  name,
        COUNT(IF(remarks = 'On time', 1, NULL)) `On time`,
        COUNT(IF(remarks = 'Late', 1, NULL)) `Late`,
        COUNT(IF(remarks = 'Absent', 1, NULL)) `Absent`  
FROM    tbl
GROUP   BY name
于 2013-02-07T07:09:26.213 に答える