如何使用 PHP
从 SQL 中echo
整天的最高厘米值
这是我的数据库:
-------------------------------
id | date | centimeter
------------------------------
1 | 2014-01-31 | 160
2 | 2014-02-28 | 800
3 | 2017-03-31 | 23
4 | 2016-04-30 | 130
5 | 2016-04-30 | 600
6 | 2017-03-31 | 700
7 | 2014-03-28 | 200
我希望以这种方式用 PHP 来回应它:
2017-03-31 700
2016-04-30 600
2014-03-28 200
*我希望白天只回显1个最高厘米
答案 0 :(得分:3)
select date, max(centimeter)
from your_table
group by date
答案 1 :(得分:0)
使用PDO
$SQL = "SELECT date , MAX(centimeter) FROM TABLE_NAME GROUP BY date";
$connection = new PDO('mysql:host=HOST;dbname=DB_NAME;charset=utf8', 'USER_NAME', 'PASSWORD');
$stmt = $connection->prepare($SQL)
if($stmt)
{
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
}
答案 2 :(得分:0)
您可以尝试这可能会对您有所帮助
SELECT table,MAX(厘米)from table_name GROUP BY by date ORDER BY date DESC;
答案 3 :(得分:0)
选择max(mytbl.centimeter)为centimeterMax,SUBSTR(mytbl.date,9,2)作为DayOnly(SELECT * FROM mytbl)作为mytbl组by DayOnly