我正在使用How to do a FULL OUTER JOIN in MySQL?的答案在MySQL 5.7中进行完全外部联接。
但是,我不确定如何为子表添加别名,以便查询为右联接使用与左联接相同的表(甚至不确定MySQL是否会在后台进行优化)
代码如下:
List<int> filtered(List<Abc> list1, List<Abc> list2) {
Set<String> dataStrings = list2.stream()
.map(x -> x.dataString))
.collect(Collectors.toSet());
return list1.stream()
.filter(x -> dataStrings.contains(x.dataString))
.map(x -> x.rowNum)
.collect(Collectors.toList());
}
查询本身将返回错误:
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;
答案 0 :(得分:1)
因为您查询select cell as hdi_social_cell
所以你必须编码
on social_hdi.hdi_social_cell = social_ml.hdi_social_cell