Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 mysql 数据库,其中我有两个datetime字段,一个是start_date另一个是end_date. 所以让我们说scorer1有一个start_date和end_date| 同样scorer2有 astart_date和end_date。
datetime
start_date
end_date
现在我怎样才能得到所有得分手的平均天数?
您可以使用mysql选择日期之间的差异:
SELECT SUM(DATEDIFF(end_date, start_date)) as difference_in_days, COUNT(id) as total_rows FROM table
这将为您提供总天数差异以及它适用的总行数。
然后,一旦你从数据库中提取了它,使用一些 PHP 来计算平均值:
$average = $row['difference_in_days'] / $row['total_rows'];