[英]Count total item types and number in a column in MYSQL
假设我有一列包含类型之类的值
CPU
CPU
CPU
VDU
VDU
我想计算像CPU这样的项目在该列中的次数。
我的查询
select COUNT( * ) as total from `table` where `types` like "%CPU%"
但在这里我知道有一个名为cpu的项目。 我可以编写一个查询,让我知道某个值出现的次数。 就像查询应该返回 CPU:3 VDU:2......
根据 P.Salmon 的评论,您可以使用GroupBy
来实现它,它看起来像下面这样
select COUNT(*) as total, `types`
from `table`
where `types` like "%_your_filter_condition_here_%"
group by `types`
这是我让它工作的方式
select COUNT(*) as total, `DeviceType`
from `inventory-core-table`
group by `DeviceType`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.