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.
私は2つのdatetimeフィールドを持つmysqlデータベースを持っています.1つはstart_dateもう1つはend_date. それで、 scorer1にstart_dateand end_date|があるとしましょう。同様に、 scorer2にはstart_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
これにより、合計日数の差と、それが適用される行の合計が得られます。
次に、DB からそれを取得したら、PHP を使用して平均を算出します。
$average = $row['difference_in_days'] / $row['total_rows'];