我正在尝试从 2 个不同的表中选择 php 中 2 个日期之间的平均时间。
我有这个:
$sql="select *, avg(end_date - start_date) as avg_days from tickets where deleted = '' and DAY(datetime) = '04' and MONTH(datetime) = '".date("m")."' and YEAR(datetime) = '".date("Y")."' group by assigned_to";
但我希望能够从表中的列和表中的列中datetime
计算出平均“响应”时间。tickets
startdate
ticket_updates
ticket_seq
表中的 与表中的列ticket_updates
链接,因此我需要选择从表中创建的第一行,该表与表中的选定行链接ticketnumber
tickets
ticket_updates
tickets
我努力了:
$sql="select tickets.*, avg(tickets.datetime - ticket_updates.timestart) as avg_days from tickets, ticket_updates where tickets.ticketnumber = ticket_updates.ticket_seq and deleted = '' and DAY(datetime) = '04' and MONTH(datetime) = '".date("m")."' and YEAR(datetime) = '".date("Y")."' group by assigned_to";
但没有返回任何内容,当我在 mysql 中运行时,我得到:
#1052 - Column 'datetime' in where clause is ambiguous