我有两个表,第一个表看起来像
键 | |
---|---|
键1 | 字1 |
键1 | word2 |
键1 | word3 |
键2 | word4 |
键2 | word5 |
键3 | word6 |
这应该会执行得更好工作示例在这里
select t1_key,t2_key,combined,count(t1_key) from (
select aggr.t1_key ,aggr.t2_key ,(select STRING_AGG(value,' ') from table2 where t2_key = aggr.t2_key ) as combined from
(select t1_key,t2_key from table1 left join table2 on table1.value = table2.value ) as aggr ) as whole
group by t1_key,t2_key,combined