mysqli结果行(带乘法)

时间:2018-01-24 12:53:03

标签: mysqli

如何使它成倍增加,而不是求和 的 table.sql

CREATE DATABASE IF NOT EXISTS people;   
CREATE TABLE IF NOT EXISTS people.`people` ( `id` int(11) NOT NULL 
AUTO_INCREMENT, `nr` int(11) NOT NULL, `date` date NOT NULL, `hour` time NOT 
NULL, `course` varchar(255) NOT NULL, PRIMARY KEY (`id`)); 
INSERT INTO `people` (`id`, `nr`, `date`, `hour`, `course`) VALUES (1, 1, '2018-01-19', 
'12:00:00', '1.9'), (2, 2, '2018-01-19', '14:00:00', '2.25'), (3, 2, '2018-
01-19', '16:00:00', '2.25'), (4, 3, '2018-01-20', '14:00:00', '2.25'), (5, 
3, '2018-01-20', '00:00:00', '1.55'), (6, 3, '2018-01-20', '00:00:00', 
'1.55'), (7, 4, '2018-01-20', '00:00:00', '1.75'), (8, 5, '2018-02-08', 
'00:00:00', '1.55');

的index.php

$link = mysqli_connect("localhost", "root", "", "table");  
$query=mysqli_query($link,"SELECT course, data, SUM(course) as total FROM (SELECT distinct data, course FROM  tabela) as obo GROUP BY data");
while($row=mysqli_fetch_array($query))
{
    $data=$row['data'];
    $total=$row['total'];
    //$total=($row['course']*?); 
    echo "Date: ".$data." ";
    echo "Sum: ".$total."<br /><br />";
}

图像:

enter image description here

0 个答案:

没有答案