Postgresql中的复杂分组查询

时间:2018-04-16 07:58:27

标签: sql postgresql group-by

我在单个游标中有以下数据,但我想将此数据写入另一个表中,每个成员都有一行。

查询:

SELECT member__c, partner_category__c ,
      COALESCE( NULLIF(to_char(activity_transaction_date__c,'Mon'),'') , 'Mon' ) as month ,to_char(activity_transaction_date__c,'YYYY') as year ,
      COALESCE( NULLIF(sum(transaction_reward__c),0) , '0' ) as prog_amt,
      exported_id__c,sfid
FROM h_activity1
GROUP BY member__c,partner_category__c,month,year,exported_id__c,sfid
ORDER BY month,member__c,partner_category__c,year,exported_id__c,sfid;

enter image description here

每个类别的总数应填入相应的列和对于每个成员,应该只有1行。如屏幕截图所示

0 个答案:

没有答案