从2张桌子获得平均值?

时间:2016-12-16 17:07:47

标签: mysql sql impala

我需要帮助sql命令〜 感谢您的帮助^^

所以我有2张桌子

Table information

如何从这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

非常感谢!

1 个答案:

答案 0 :(得分:1)

您可以将这两个表作为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;