SELECT 仅 Group BY 计数 return 值为 2

SELECT COUNT with Group BY only return value of 2

我有 6 条记录,其中 3 条具有相同的学校,我想得到计算我的数据库中有多少所学校的结果,但它只有 returns 2 的值

$tblnum1 = "SELECT COUNT(*) AS ttldata FROM engoralgrade3 WHERE Years = '$yrr' GROUP BY School";
$tblnum = mysqli_query($conn, $tblnum1);
$tblnm = mysqli_fetch_array($tblnum);

echo $tblnm['ttldata'];//input should be 3

This what my data base looked like

我查过你的table,每个学校都有2行。 也许你想计算有多少不同的学校,所以将 sql 更改为:

select count(distinct School )from engoralgrade3

或者你想区分学校名称,试试:

select distinct School from engoralgrade3

您可以试试这个查询它会起作用

$tblnum1 = "SELECT * FROM engoralgrade3 WHERE Years = '$yrr' GROUP BY School";
$tblnum = mysqli_query($conn, $tblnum1);
$tblnm = mysqli_num_rows($tblnum);

echo $tblnm ;

可能是数据库中所有六个记录的 var $yrr 都不相同,这导致 make returnred 值是 2 而不是 3。