Я делаю полное внешнее объединение в MySQL 5.7, используя ответ от Как выполнить ПОЛНОЕ ВНЕШНЕЕ СОЕДИНЕНИЕ в MySQL? .
Однако я не уверен, как добавить псевдонимы для вложенных таблиц, чтобы запрос использовал ту же таблицу для правого объединения, что и для левого объединения (даже не уверен, оптимизирует ли 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'