Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用group函数回显计数查询_Php_Mysql - Fatal编程技术网

Php 如何使用group函数回显计数查询

Php 如何使用group函数回显计数查询,php,mysql,Php,Mysql,我是mySQL的新手,因此我只是在寻找一个非常简单的计数查询,但我在网上没有找到任何真正清晰的解释 我想做的是 按年龄计算学龄儿童群体的数量我想你需要这样的东西: SELECT age, COUNT(*) FROM your_table GROUP BY age ORDER BY age; 此查询将打印每个年龄的年龄和子代数。在Mysql中,您可以执行以下sql命令: “按年龄从儿童组中选择计数(nr_儿童)” 或在php中: $servername = "localhost"; $usern

我是mySQL的新手,因此我只是在寻找一个非常简单的计数查询,但我在网上没有找到任何真正清晰的解释

我想做的是


按年龄计算学龄儿童群体的数量

我想你需要这样的东西:

SELECT age, COUNT(*)
FROM your_table
GROUP BY age
ORDER BY age;

此查询将打印每个年龄的年龄和子代数。

在Mysql中,您可以执行以下sql命令:
“按年龄从儿童组中选择计数(nr_儿童)”

或在php中:

$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "select * from children group by age";
$children = $conn->query($sql);
$nr_child = mysqli_num_rows($children);
echo $nr_child;

你能发布你的表格和你的查询吗?
Select count(*)from table\u name group by age
Select age,count(*)from table\u name group by age
(你在Select中缺少年龄)这是查询(“Select gendar,count(teachercode)from teacher group by gendar”),表格有两个字段。他们不是生态正常的名字姓氏这是我的代码,但工作不正常