PHP Seleccionar promedio entre 2 fechas
Frecuentes
Visto 206 veces
0
i am trying to select the average time between 2 dates in php from 2 different tables.
tengo esto:
$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
columna en el tickets
mesa y el startdate
columna en el ticket_updates
mesa.
al ticket_seq
en el capítulo respecto a la ticket_updates
table links with the ticketnumber
columna en el 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
mesa
Yo he tratado:
$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
1 Respuestas
0
I have managed to fix the issue by using this query:
$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(tickets.datetime) = '04'
AND MONTH(tickets.datetime) = '".date("m")."'
AND YEAR(tickets.datetime) = '".date("Y")."'
GROUP BY
tickets.assigned_to
";
Respondido el 10 de Septiembre de 13 a las 01:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php mysql sql or haz tu propia pregunta.
What's the part causing you difficulty? - Dan Bracuk
see my question edit.. - charlie
The error message means you have to qualify the field datetime with one of the tables in your where clause. You know how to do that I trust. - Dan Bracuk
im not too sure how to do that? - charlie