[英]How to count the distinct values repeated in table
I have a table which has columns as id | 我有一个表,其中的列为id | BSC |
BSC | Size .Now each column has some data in it like
大小。现在每列中都有一些数据,例如
id | BSC | Size
1 Tambaram 100
2 Tambaram 200
3 Perungudi 100
4 Tambaram 100
5 Perungudi 200
I want to find the count of the number of distinct values and how many times each of those distinct values are repeated like 100 is repeated 3 times and 200 for 2 times. 我想找到不同值的数量以及这些不同值分别重复多少次,例如100次重复3次,200次重复2次。 I have used COUNT and DISTINCT and getting the count of the number of distinct values.
我使用了COUNT和DISTINCT来获取不同值的数量计数。 But i also want to know how many times those are repeated.
但是我也想知道重复多少次。 Here is my code:
这是我的代码:
<?php
include 'db.php';
if (!$link)
{
die('Could not connect: ' . mysqli_connect_errno());
}
$result = mysqli_query($link,"SELECT COUNT(DISTINCT Size) FROM Query_count");
if($result){
$data = mysqli_fetch_array($result);
echo $data[0];
}
$link->close();
?>
You are missing a group by
like 您像错过了一个
group by
SELECT COUNT(DISTINCT Size) as sizes
FROM Query_count
GROUP BY BSC
If you want to know how many time single SIZE values are present you shuold use 如果您想知道单个SIZE值存在多少时间,请使用old
SELECT SIZE, COUNT(*) AS RN
FROM QUERY_COUNT
GROUP BY SIZE
You are missing group by size: 您缺少按大小分组:
SELECT size, count(*) as count from Query_count
GROUP BY size
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.