我正在尝试根据事件类型有条件地将一个主事件表连接到另外三个表。选择语句可以正常工作,返回了我期望的结果集,但是当我添加JOIN语句时,出现了错误,提示找不到列别名:
SELECT
event.type as type,
IF(type = 'birthday', event.target_id, NULL) as birthday_id,
IF(type = 'graduation', event.target_id, NULL) as graduation_id,
IF(type = 'wedding', event.target_id, NULL) as wedding_id
FROM event
LEFT OUTER JOIN birthday ON birthday_id = birthday.id
LEFT OUTER JOIN graduation ON graduation_id = graduation.id
LEFT OUTER JOIN wedding ON wedding_id = wedding.id
出现以下错误:
在“on”子句中未知列“birthday_id”
更新:好的,Sebas刚刚指出您无法在计算结果上进行连接,那么我这种方法就行不通了。那么像这样做正确的方法是什么?