PHP Select average between 2 dates
i am trying to select the average time between 2 dates in php from 2
different tables.
i have this:
$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";
but i want to be able to work out the average 'response' time from the
datetime column in the tickets table and the startdate column in the
ticket_updates table.
the ticket_seq in the ticket_updates table links with the ticketnumber
column in the tickets table so i need to select the first row created from
the ticket_updates table that links with the selected row from the tickets
table
i have tried:
$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";
but nothing is returned and when i run in mysql i get:
#1052 - Column 'datetime' in where clause is ambiguous
No comments:
Post a Comment