【问题标题】:Microsoft Access percentage of subtotalMicrosoft Access 小计百分比
【发布时间】:2020-10-19 09:19:10
【问题描述】:

我正在尝试运行以下查询以获取每个基金的国家权重。问题是你不能使用 Over/Partition。提前致谢

【问题讨论】:

    标签: sql ms-access ms-access-2010


    【解决方案1】:

    一个选项使用相关子查询:

    select fund, country, 
        1.0 * sum(marketvalue) 
            / (select sum(t1.marketvalue) from mytable as t1 where t1.fund = t.fund) 
            as country_percent
    from mytable as t
    

    【讨论】:

      【解决方案2】:

      这是两个级别的汇总 - 国家/基金级别和基金级别。一种方法是:

      select cf.*, cf.value * 1.0 / f.value
      from (select country, fund, sum(value) as value
            from t
            group by country, fund
           ) as cf inner join
           (select fund, sum(value) as value
            from t
            group by fund
           ) as f
           on f.fund = cf.fund;
           
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多