SQL统计查询

m3t*_*man 0 sql database statistics

我想收集一些统计数据,我想知道是否可以直接通过数据库查询获取一些最小值,最大值和平均值.

在过度简化中我有这样的事情:

Person  | Account
__________________
Person1 | Account1
Person1 | Account2
Person1 | Account3
Person2 | Account4
Person2 | Account5
..................
Run Code Online (Sandbox Code Playgroud)

我想查找一个人拥有的最大,最小和平均帐户数.这可能是SQL查询吗?

pod*_*ska 6

select
    min(accountcount),
    avg(accountcount),
    max(accountcount)
from
(
    select 
        person, count(*) as accountcount
    from 
        yourtable
    group by person
) v
Run Code Online (Sandbox Code Playgroud)

AVG 将返回均值,而不是任何其他类型的平均值.