计算最后一行中每一列的平均值

八月

我试图在表格末尾计算每列的平均值。我似乎无法正确地处理这个问题。

这是我的查询:

SELECT profiles.id, min (total_connections_average) from profiles

inner join connections ON from_profile_id = profiles.id

    inner join (

        select sq.from_profile_id,

        count (sq.countn) as total_connections_average 
            from (

            select from_profile_id, cast (accepted_at as date), count (*) as countn from connections

            group by from_profile_id, cast (accepted_at as date)
            ) as sq

        group by sq.from_profile_id
        
            ) sq ON sq.from_profile_id = profiles.id
    
where profiles.id in ('1','2','3','4','25','26')
    
group by profiles.id

查询的结果数据:

ID 分钟
1 31
2 11
3 21
4 8
25 9
26 6

我想在最后有一行,对每一列进行平均计算,例如:

ID 分钟
1 31
2 11
3 21
4 8
25 9
26 6
10.16666667 14.33333333

非常感谢任何帮助。

同上拉赫马特

我能想到的最好的方法是与前面的查询合并。这是我想出的快速修复

SELECT profiles.id, min (total_connections_average) min from profiles

inner join connections ON from_profile_id = profiles.id

inner join (

select sq.from_profile_id,

count (sq.countn) as total_connections_average
from (

select from_profile_id, cast (accepted_at as date), count (*) as countn from connections

group by from_profile_id, cast (accepted_at as date)
) as sq

group by sq.from_profile_id

) sq ON sq.from_profile_id = profiles.id

where profiles.id in ('1','2','3','4','25','26')

group by profiles.id

#this is union for average last column

union

select avg(agg.id), avg(agg.min)
from (
SELECT profiles.id, min (total_connections_average) min from profiles

inner join connections ON from_profile_id = profiles.id

inner join (

select sq.from_profile_id,

count (sq.countn) as total_connections_average
from (

select from_profile_id, cast (accepted_at as date), count (*) as countn from connections

group by from_profile_id, cast (accepted_at as date)
) as sq

group by sq.from_profile_id

) sq ON sq.from_profile_id = profiles.id

where profiles.id in ('1','2','3','4','25','26')

group by profiles.id
) agg

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

pandas:计算一列中每一行的numpy数组的平均值

计算文件中每一列的平均值

R计算行平均值,每一行显示不同的列,如另一列所示

对于每一行,计算MySQL中最后20行的平均值

根据一组条件为多列中的每一行计算自定义平均值

spark-计算2列或更多列中的平均值,并在每一行中放入新列

提取 Pandas 中每一列的平均值

MYSQL中每一行的平均值

从特定列的数据帧计算每一行的多种平均值

特征矩阵取矩阵的每一行的平均值(计算列向量的质心)

Python-计算CSV文件中每一列的平均值

计算 R 中大型数据帧列表中每一行的平均值

如何计算数据帧每一行中特定值的平均值?

计算数据框中每一行的滚动平均值

如何计算R中每一行的数据帧块的累积平均值

计算列的平均值,第一行除外

计算列中同一行内多个值的平均值

在查询底部显示每一列的平均值

根据熊猫中的另一列计算一列的平均值

所选索引上每一行的平均值

计算包含值列表的每一行的平均值

计算具有间隔的每一行的平均值

我想为每个 book_id 选择最后一行中的 # users_read 并计算平均值

一行(两列的平均值)和同一行(另一列的值)的总和

如何旋转并获取每一列的平均值到行

用Python用该列的平均值减去数据框中的每一列

根据另一列中的值获取每列的平均值

PowerQuery:取多列中每一列的平均值

计算每5行特定列的平均值,并在pandas数据框中选择另一列的最后一个数据(第五个)