SQL query to count in group by with specific condition

前端 未结 2 1166
轮回少年
轮回少年 2021-01-24 12:28

My table data:

id      fieldId  Name   Text
----    ------  -----   ----
1        101    name1   a1
2        102    name2   a2
3        101    name1   a1
4               


        
2条回答
  •  广开言路
    2021-01-24 12:43

    Here.

    SELECT
        `Name`,
        COUNT(*) AS 'fieldId',
        COUNT(IF(`Text` REGEXP '^a[1-3]',1,NULL)) AS 'a1a2a3'
    FROM (SELECT * FROM `items` GROUP BY `Name`,`Text`) t1
    GROUP BY `Name`;
    

提交回复
热议问题