Monday, 19 August 2013

Get a result by comparing two tables with an identical column

Get a result by comparing two tables with an identical column

mysql> select * from on_connected;
+----+-----------+-------------+---------------------------+---------------------+
| id | extension | destination | call_id | created_at
|
+----+-----------+-------------+---------------------------+---------------------+
| 11 | 1111111 | 01155555551 | 521243ad953e-965inwuz1gku | 2013-08-19
17:11:53 |
+----+-----------+-------------+---------------------------+---------------------+
mysql> select * from on_disconnected;
+----+-----------+-------------+---------------------------+---------------------+
| id | extension | destination | call_id | created_at
|
+----+-----------+-------------+---------------------------+---------------------+
| 1 | 1111111 | 01155555551 | 521243ad953e-965inwuz1gku | 2013-08-19
17:11:57 |
+----+-----------+-------------+---------------------------+---------------------+
1 row in set (0.00 sec)
There is a time difference of 4sec between the two. I would like to
calculate the difference using a query of some type. I'm aware of
TIMEFIFF() and joins but lack the skills to form the query at this point.
Here's my attempt thus far:
SELECT TIMEDIFF(to_seconds(od.created_at), to_seconds(oc.created_at))
FROM on_connected oc
JOIN on_disconnected od
ON oc.call_id=od.call_id
WHERE call_id='521243ad953e-965inwuz1gku';
Mysql reports:
ERROR 1052 (23000): Column 'call_id' in where clause is ambiguous

No comments:

Post a Comment