0
In a table, I have two fields: entry_time and exit_time. I want to subtract each record (Exit - entry) to find the wait of each client, add all the waits, and take an average of that sum by the number of clients.
There are some conditions that are already in the query but in essence what I want is:
sum(exit_time - entry_time) div count(*)
I have a query that brings me a display in the two generated fields that I need to do DIV():
SELECT SUM(espera) soma, COUNT(*) as totalregistros FROM
(SELECT timestampdiff(minute,queue_entry_time,queue_exit_time) espera
FROM queue_element where status='done') soma;
+------+----------------+
| soma | totalregistros |
+------+----------------+
| 45 | 8 |
+------+----------------+
If I try to divide one field by another I get the following error:
SELECT soma div totalregistros from (
SELECT SUM(espera) soma, COUNT(*) as totalregistros
FROM (SELECT timestampdiff(minute,queue_entry_time,queue_exit_time) espera
FROM queue_element where status='done') soma);
ERROR 1248 (42000): Every derived table must have its own alias
However I cannot see which subselect is without alias. Remember that I cannot use procedures or temporary table in my scenario.
Could someone point out my mistake? Thank you!
Thank you very much! It worked perfectly!
– Jhonatan Cruz