不确定这是哪里来的。我的目的是将ROUND(AVG(duration))除以lead_at和qualified_at(第二个子查询)的差异
SELECT (SELECT first_name
FROM users_permissions p WHERE p.user_id=a.assistant_id LIMIT 1) as Name, (SELECT u.lead_at, u.qualified_at FROM users u INNER JOIN aircalls ON u.id=aircalls.user_id WHERE u.qualified_at - u.lead_at) AS Difference, ROUND(AVG(duration)), count(id)
FROM aircalls a
WHERE assistant_id IS NOT NULL
AND status='Call Connected'
AND type='user'
AND EXISTS (SELECT u.id FROM users u INNER JOIN aircalls ON u.id=aircalls.user_id AND u.status NOT IN (1,7))
AND EXISTS (SELECT p.user_id FROM users_permissions p INNER JOIN aircalls ON p.user_id=aircalls.user_id AND p.is_agent NOT IN (1))
AND year(a.created_at)=2019
GROUP BY(SELECT first_name
FROM users_permissions p WHERE p.user_id=a.assistant_id LIMIT 1)
答案 0 :(得分:1)
问题在您的第二选择(差异)中,而不是推论两个值,您只是将它们都用逗号分隔。另外,where
中的select
子句没有有效值。
是:
SELECT u.lead_at, u.qualified_at FROM users u INNER JOIN aircalls ON u.id=aircalls.user_id WHERE u.qualified_at - u.lead_at) AS Difference
这是该错误行的更正:
(SELECT u.lead_at - u.qualified_at FROM users u INNER JOIN aircalls ON u.id=aircalls.user_id) AS Difference