MySQL:连接两个信息,return一个虚拟列,依次与该列进行INNER JOIN

MySQL: Concatenate two information, return a virtual column and in sequence perform an INNER JOIN with the column

在我的项目中,我需要创建一个包含 Concat 信息的 Column,如下所示: CONCAT('SIP/', 名称) AS sipAgent.

这有效,但是当我尝试与列 sipAgent 进行内部连接时,出现错误:(

在内部联接之后,我需要对

的每个结果求和

像那样:

----------------------------------
| NAME | sipAgent | notAnswered  |
----------------------------------
| aaa  | SIP/aaa  |    132       |
| bbb  | SIP/bbb  |    50        |
----------------------------------

name是agent的引用,sipAgent是'SIP/'+name,noAnswered是inner join返回的行数

这是我的 'test-query':

SELECT *, CONCAT('SIP/', tab_sippeers.name) AS sipAgent, SUM(queue_log.event) as notAnswered
FROM 'ipbx.tab_sippeers'

join 'queue_log' on tab_sippeers.sipAgent = queue_log.agent

但是,正在返回错误... 抱歉英语不好,非常感谢您的帮助!

查询在其他方面看起来不正确,但您可以在连接中连接

   SELECT *, CONCAT('SIP/', tab_sippeers.name) AS sipAgent, SUM(queue_log.event) as notAnswered
FROM `ipbx.tab_sippeers`
join `queue_log` on CONCAT('SIP/', tab_sippeers.name)  = queue_log.agent;

和 table 名称和列名应该用反引号而不是单引号括起来,如果你想把它们括起来的话。 When to use single quotes, double quotes, and back ticks in MySQL