从2个表中获取平均值?

问题描述:

我需要的SQL命令帮助〜 感谢您的帮助提前^^从2个表中获取平均值?

所以我有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 

非常感谢你的结果!

+2

嗨,欢迎SO。请更新您的问题,以包含您的表格结构,每个样本的一些示例数据,然后包括您正在查找的结果。如果您有任何疑问,请将其包括在内。看看:http://*.com/help/how-to-ask了解更多关于加强你的问题的信息。 – gmiley

+0

加入国家代码表,然后计算'(table1.frequency + table2.frequency)/ 2'来获得平均值。 – Barmar

+0

你做了什么编码尝试? – happymacarts

您可以查询两个表的UNION ALL然后使用它作为一个子查询与GROUP BY并在Frequency列的AVG()

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;