Mysql查询从不包含确切值的记录中获取计数

时间:2018-01-24 13:09:51

标签: mysql

假设我有这张表:

id       |     name      |      date
1               aaa               11
2               aaa|bbb           11
3               bbb|ccc           11
4               aaa|ccc           11
1               aaaX              12
2               aaaX|bbbY         12
3               bbbY|cccY         12
4               aaaZ|cccZ         12

预期数据:

date : 11,    name: aaa,    count: 3
date : 11,    name: bbb,    count: 1
date : 11,    name: ccc,    count: 2
date : 12,    name: aaa,    count: 3
date : 12,    name: bbb,    count: 2
date : 12,    name: ccc,    count: 2

我想获取按日期分组的名字计数。 我试过这个查询:

SELECT name, COUNT(*) AS count
FROM mytable
WHERE name LIKE "%aaa%" OR
name LIKE "%bbb%" OR
name LIKE "%ccc%"
GROUP BY name    

我得到的结果是名字aaa,bbb,ccc,aaa | bbb,aaa | ccc,aaaX | bbbY,...

获得此项的查询是什么?

0 个答案:

没有答案