我有两个查询 A & B 说,如下:
SELECT SUM(TIME_TO_SEC(TIMEDIFF(od.created_at, oc.created_at))) AS `sum (secs)`
FROM on_connected oc
JOIN on_disconnected od ON od.call_id = oc.call_id
WHERE oc.ext_num = 3205006;
+------------+
| sum (secs) |
+------------+
| 14 |
+------------+
1 row in set (0.00 sec)
和
SELECT count(TIME_TO_SEC(TIMEDIFF(od.created_at, oc.created_at))) AS `total calls`
FROM on_connected oc
JOIN on_disconnected od
ON od.call_id = oc.call_id
WHERE oc.ext_num = 3205006;
+-----------------+
| total calls |
+-----------------+
| 3 |
+-----------------+
1 row in set (0.00 sec)
我想将结果用于 MySQL 中的除法运算,如下所示:
SELECT A DIV B
这会给我一个 14/3 = 4 的结果。我尝试了什么?
SELECT
(SELECT SUM(TIME_TO_SEC(TIMEDIFF(od.created_at, oc.created_at))) AS `sum (secs)`
FROM on_connected oc
JOIN on_disconnected od ON od.call_id = oc.call_id) a
INNER JOIN
(SELECT count(TIME_TO_SEC(TIMEDIFF(od.created_at, oc.created_at))) AS `total calls`
FROM on_connected oc
JOIN on_disconnected od ON od.call_id = oc.call_id) b
WHERE oc.ext_num = 3205006;
INNER JOIN 语法妨碍了我的 DIV 运算符吗?