我想计算所有针对id的条目
我使用了这个查询
select count(*) from table1 group by `id`
问题是我的表有3条记录
id A has 2 records
id B has 1 record
当我使用php运行此查询时,它给了我2个输入
$mysqli = new mysqli("localhost","root", "", "db");
$query = $mysqli->prepare("SELECT COUNT(*) FROM `tble1` GROUP by `ID`");
$query->execute();
$query->store_result();
$rowsaff = $query->num_rows;
echo $rowsaff;
答案 0 :(得分:0)
您必须选择不同ID的计数:
$query = $mysqli->prepare("SELECT COUNT(distinct `ID`) FROM `tble1`");