从2个表中获得平均值?

zhte4eai  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(445)

我需要sql命令方面的帮助~提前谢谢你的帮助^^
所以我有两张table

我怎样才能从这个2表中得到平均值。
我想要的结果是

Country Code 65 has 49.5 Frequency
Country Code 42 has 17 Frequency
Country Code 33 has 18 Frequency
Country Code 11 has 5 Frequency

非常感谢你!

628mspwn

628mspwn1#

可以将这两个表作为一个表进行查询 UNION ALL 然后用它作为子查询 GROUP BY 和一个 AVG()Frequency 列:

select cntry_cde, Avg(freq) as freq_avg
from 
(
    select t1.cntry_cde, t1.freq
    from avg_call t1
    union all
    select t2.cntry_cde, t2.freq
    from calls_at_one t2
)
group by cntry_cde;

相关问题