[英]Mysql count number of rows which have same value
I have in my table 3 rows. 我的桌子上有3行。 2 of them with the same value (valueA) on field status and the 3-rd one with another value (valueB). 其中两个具有相同的字段状态值(valueA),而第三个具有另一个值(valueB)。
What i want to do is to display a message to show me how many rows with the same value exists. 我想要做的是显示一条消息,向我显示存在相同值的行数。 Example below: 下面的例子:
EX: There are 2 status value in the database There are 1 status value in the database 例如:数据库中有2个状态值数据库中有1个状态值
How can i achive that? 我怎样才能做到这一点? Thank you. 谢谢。
You need group by and count 您需要分组并计数
select your_column_name, count(*) from your_table
group by your_column_name;
in your case assuming status
is th column name 在您的情况下,假设status
为列名
select concat("there is " , count(*), " status in your db") from your_table
group by status;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.