Thursday, 18 June 2020

How to get the count of each distinct value in a column in MySQL

<?php
include "connect.php"; //here your database connection page
$sql = "SELECT id ,min,max, COUNT(max) tot FROM dogebtccandle group by max having count(max) > 1 order by tot desc";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()){
echo "id: " . $row["id"]. " - Name: " . $row["min"]. " max " . $row["max"]. "count " . $row["tot"]. "<br>";
}}
else {echo "count no";}

?>
my database details 
table name dogebtccandle 
column : id , min , max

idminmax
1 0.00000026247 0.00000026268
2 0.00000026247 0.00000026303
3 0.00000026247 0.00000026264
4 0.00000026246 0.00000026310
5 0.00000026211 0.00000026332
6 0.00000026211 0.00000026324
7 0.00000026178 0.00000026310
8 0.00000026180 0.00000026279
9 0.00000026178 0.00000026296
10 0.00000026179 0.00000026289
11 0.00000026179 0.00000026299
12 0.00000026167 0.00000026290
13 0.00000026167 0.00000026278
14 0.00000026152 0.00000026248
15 0.00000026178 0.00000026248
16 0.00000026138 0.00000026348
17 0.00000026255 0.00000026346
18 0.00000026225 0.00000026397
19 0.00000026225 0.00000026349
20 0.00000026250 0.00000026361