【发布时间】:2017-09-15 07:26:13
【问题描述】:
如何在PHP 或MySQL 中创建一个结果,例如显示2005 年,并对所有结果求和
示例输入
-------------------------
Date \ Quantiti
-------------------------
12-05-2005 \ 5
-------------------------
23-08-2005 \ 8
-------------------------
11-02-2006 \ 4
-------------------------
26-09-2006 \ 2
-------------------------
示例输出
---------------------------
year \ Total
---------------------------
2005 \ 13
---------------------------
2006 \ 6
---------------------------
<?php
$sql = "SELECT * FROM mytable ORDER BY date DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$date = $row["date"];
$quantiti = $row["quantiti"];
// here i need code for each new year
}
} else {
}
?>
【问题讨论】:
-
大写字母用于标题。您能否编辑您的问题并使其可读。
-
你应该看看
YEAR()和SUM():dev.mysql.com/doc/refman/5.7/en/group-by-functions.html