在表格中选择“Ratio_to_report”

问题描述 投票:0回答:1

我想选择总价格的比例或id_lot制作的id_programme:这里是表格:

 id_lot | id_programme | surface | prix 
--------+--------------+---------+------
    101 |            1 |      30 |  180
    201 |            1 |      30 |  185
    391 |            2 |      40 |  145

我试过这个:

     select id_lot,id_programme ,                                                    
     ratio_to_report(sum(prix)) over(partition by id_programme) as 
     ratio
     from t
     group by id_lot,id_programme;;

我收到此错误:

选择id_lot,id_programme,ratio_to_report(sum(prix))over(... ^ HINT:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。

sql postgresql
1个回答
0
投票

您可以显式执行ratio_to_report()的计算。这有用吗?

select id_lot, id_programme,  
       sum(prix) / sum(sum(prix)) over (partition by id_programme) as ratio
from t
group by id_lot, id_programme;

Here是使用Postgres的db <>小提琴。

© www.soinside.com 2019 - 2024. All rights reserved.