我想使用php mysql
计算并显示下表中列中的每个重复值name
AAA
BBB
BBB
BBB
AAA
CCC
结果应该如下
AAA-2
BBB-3
CCC-1
答案 0 :(得分:3)
你需要:
select name,count(1) from yourtable group by name
如果您需要带连字符( - )
的输出select concat(name,'-',count(1)) from yourtable group by name
答案 1 :(得分:3)
select name, count(name) as count from table_name group by name
答案 2 :(得分:2)
试试这个,
Thread
答案 3 :(得分:1)
SELECT name, COUNT(name) c_name FROM tablename GROUP BY name HAVING c_name>1
答案 4 :(得分:-1)
<?php
require_once('connection.php');
$result=mysqli_query($conn,
"SELECT colum_name, concat(count(1),'-',colum_name)
as colum_name
FROM table_name
group by colum_name
order by colum_name desc");
while ( $data=mysqli_fetch_assoc($result)) {
echo $data['colum_name']."<br>";
}