QueryBuilder-在innerJoin中使用Select

时间:2018-07-06 18:56:07

标签: symfony query-builder

有人可以帮助我吗? 我需要将我的SQL查询更改为querybuilder。我不知道如何在innerJoin内部使用select。

这是我的SQL查询:

SELECT 
      user.id,
      analytic_youtube_demographic.age_group, 
      analytic_youtube_demographic.percentage
FROM 
    user
INNER JOIN user_youtube ON user_youtube.id = user.id
INNER JOIN analytic ON analytic.id = user_youtube.analytic_id
INNER JOIN analytic_youtube_demographic ON analytic_youtube_demographic.analytic_id = analytic.id
INNER JOIN 
(
SELECT analytic_youtube_demographic.id as id, MAX(analytic_youtube_demographic.percentage) max
from user
INNER JOIN user_youtube ON user_youtube.id = user.id
INNER JOIN analytic ON analytic.id = user_youtube.analytic_id
INNER JOIN analytic_youtube_demographic ON analytic_youtube_demographic.analytic_id = analytic.id
GROUP BY user.id
) AS T ON analytic_youtube_demographic.percentage = T.max
WHERE analytic_youtube_demographic.age_group IN ('18-24')

非常感谢您的帮助。

0 个答案:

没有答案