如何获取mysql中具有重复值的记录数

时间:2016-01-20 06:51:49

标签: php mysql

我有一个包含播放器和状态的表,这个表没有被破坏,它有重复的条目,如下所示:

player_id      status
----------------------
1           100
2           100
2           101
3           100
1           101
2           101

如您所见,此记录重复:2,101

如何使用mysql查询找到此类记录?

我试过了:

select * from player group by player_id, status having count(status) > 1但它没有帮助。

8 个答案:

答案 0 :(得分:2)

您可以SELECT重复记录,如下所示:

SELECT COUNT(*) as total,player_id,`status`
FROM `player` 
GROUP BY player_id,`status` 
HAVING total > 1;

答案 1 :(得分:1)

在外部查询中执行此操作,例如

select * from (
select *, count(*) as rowcount
from player 
group by player_id, status ) tab
where rowcount > 1

答案 2 :(得分:1)

  

您可以尝试此查询。

$qrys = <<<QUERY
select s.id, t.* 
from player s
join (
    select player_id, status, count(*) as qty
    from player
    group by player_id, status
    having count(*) > 1
) t on s.player_id = t.player_id and s.status = t.status
QUERY;
  

如果要删除重复记录,请使用此脚本

$delres=  mysql_query($qrys);
$player_id = 0;
$status = 0;
while ($r=  mysql_fetch_array($delres)){
    if($player_id == $r['player_id'] && $status == $r['status'])
    mysql_query("DELETE FROM player WHERE id=".$r['id']);
    $player_id = $r['player_id'];
    $status = $r['status'];
}

答案 3 :(得分:0)

试试这个:

select * from player p 
inner join ( select player_id, count(*) as duplicate 
from player group by player_id 
having count(*) > 1) pp 
on p.player_id = pp.player_id

答案 4 :(得分:0)

您的查询接近它只是在其中进行了一些更改,为每个选项提供计数列尝试此修改后的查询。

select *, count(status) as count from player 
 group by player_id, status having count(status) > 0 

它会给出这种类型的回复

enter image description here

答案 5 :(得分:0)

试试这个

SELECT *, COUNT(status) AS rows_count FROM player 
GROUP BY player_id, status HAVING COUNT(status) > 0 

答案 6 :(得分:-1)

你可以通过

来做到这一点
SELECT distinct player .*
  FROM player as tb1
  join player as tb2
 WHERE tb1.status = tb2.status
   and tb1.player_id < tb2.player_id

答案 7 :(得分:-1)

您只需使用SELECT `player_id`, `status`, COUNT(*) as cnt FROM `player` GROUP BY CONCAT(`player_id`, '_', `status`) HAVING cnt > 1 就可以完成此操作

player_id   status  cnt     
2           101     2

结果将是

std::vector<std::pair<float, int>> predictions;
float * pixel = output.ptr<float>( 0 );
for ( int j = 0; j < output.cols; ++j ) {
    predictions.push_back({pixel[j], j});
}
std::sort(predictions.rbegin(), predictions.rend());