查询对我来说非常正确。在查找时,查询中似乎存在优先级问题。
问题出在这一行 - group_membership_settings.group_id = groups.id
'on clause'
中的未知列groups.id
SELECT SQL_NO_CACHE `groups`.`name` AS `profile_name`, (
SELECT IF(
group_membership_settings.max_limit,
group_membership_settings.max_limit > (
SELECT COUNT(connection_memberships.id) FROM connection_memberships
WHERE connection_memberships.type = 'Connection::MenteeMembership'
AND connection_memberships.group_id = groups.id
), 1)
FROM programs
INNER JOIN roles ON roles.program_id = programs.id AND roles.name = 'student'
LEFT JOIN group_membership_settings ON group_membership_settings.group_id = groups.id AND group_membership_settings.role_id = roles.id
WHERE programs.id = groups.program_id
) AS `available_to_join` FROM `groups`
答案 0 :(得分:0)
表(别名)groups
不在 范围内。
您只能引用本地查询中表格中的列,即programs
,roles
或group_membership_settings
。
我不知道你的意图是什么,但你可能还必须在内部查询中加入groups
。