MySQL获得不同的值并计算每个的数量?

时间:2021-11-21 15:33:19

There is a status column. I need to pull all the distinct values for each one, and a number indicating how many times each unique value is in the table.

有一个状态列。我需要为每个值拉出所有不同的值,并且数字表示每个唯一值在表中的次数。

Is there a way to do that?

有没有办法做到这一点?

Thanks.

2 个解决方案

#1


16  

SELECT status, count(*) as c FROM table GROUP By status;

#2


0  

I am not sure I understand what you are after.

我不确定我明白你的意思。

When you pull distinct values, there is (by definition) one of each unique value.

当您提取不同的值时,(根据定义)每个唯一值都有一个。

Can you rephrase what you are trying to do?

你能改写一下你想做什么吗?

UPDATE

After reading another solution, I think I see what you are after.

在阅读了另一个解决方案之后,我想我知道你在追求什么。

Using SELECT COUNT(*) as given in the solution by Rufinus should do the trick.

使用Rufinus在解决方案中给出的SELECT COUNT(*)应该可以解决问题。

#1


16  

SELECT status, count(*) as c FROM table GROUP By status;

#2


0  

I am not sure I understand what you are after.

我不确定我明白你的意思。

When you pull distinct values, there is (by definition) one of each unique value.

当您提取不同的值时,(根据定义)每个唯一值都有一个。

Can you rephrase what you are trying to do?

你能改写一下你想做什么吗?

UPDATE

After reading another solution, I think I see what you are after.

在阅读了另一个解决方案之后,我想我知道你在追求什么。

Using SELECT COUNT(*) as given in the solution by Rufinus should do the trick.

使用Rufinus在解决方案中给出的SELECT COUNT(*)应该可以解决问题。