【发布时间】:2019-05-15 12:12:17
【问题描述】:
我正在使用来自How to do a FULL OUTER JOIN in MySQL? 的答案在 MySQL 5.7 中进行完全外部联接。
但是,我不确定如何为子表添加别名,以便查询使用与左连接相同的表进行右连接(甚至不确定 MySQL 是否会在后台优化它) .
代码如下:
select *
from
(select cell as hdi_social_cell, count(*) as hdi_social_cell_count
from Detector_Social_Events where streamtype='social' and source = 'hdi'
group by cell having hdi_social_cell_count > 5) social_hdi
left join
(select cell as ml_social_cell, count(*)*0.1 as ml_social_cell_count
from Detector_Social_Events where streamtype='social' and source = 'ml'
group by cell having ml_social_cell_count > 1) social_ml
on social_hdi.cell = social_ml.cell
union select * from
(select cell as hdi_social_cell, count(*) as hdi_social_cell_count
from Detector_Social_Events where streamtype='social' and source = 'hdi'
group by cell having hdi_social_cell_count > 5) social_hdi
right join
(select cell as ml_social_cell, count(*)*0.1 as ml_social_cell_count
from Detector_Social_Events where streamtype='social' and source = 'ml'
group by cell having ml_social_cell_count > 1) social_ml
on social_hdi.cell = social_ml.cell;
查询返回错误:
ERROR 1054 (42S22): Unknown column 'social_hdi.cell' in 'on clause'
【问题讨论】:
-
你的意思是错误是
'social_hdi.cell' in 'on clause'吗?我在任何地方都没有看到twitter_hdi -
是的,你是对的。我已修复错误消息。