我有以下Postgres代码,我希望Group BY "Personal CC"
,但由于显而易见的原因,我无法对聚合字段执行此操作。
如果我没有放Group BY
,那么我会收到错误的"Number of Assistant Supervisors in Same Month"
Personal CC
。
请帮我详细说明如何计算金额。是的,我做了一些研究,并且知道我们可以使用INNER JOIN,但我失败了。
对于每个赞助商,我有各个国家的每月cc。个人CC值。每个月。我想总结它们以获得一个独特的总结值
SELECT
extended_downline."Sponsor FBO ID"
,extended_downline."Sponsor Name"
,mcc.processing_month__c AS "Processing Month"
,mcc.processing_year__c AS "Processing Year"
,sum(mcc.personal_cc_mtd__c) AS "Personal CC"
,sum("Same Month") as "Number of Assistant Supervisors in Same Month"
,bool_or(mcc.current_month_active__c) AS "Current Month Active"
FROM extended_downline
LEFT OUTER JOIN connect.monthly_cc__c mcc ON mcc.distributor__c = extended_downline.sponsor_distributor__c
AND mcc.op_company__c = extended_downline."Operating Company"
AND (
(
mcc.processing_year__c = '2017'
AND mcc.processing_month__c = 10
)
)
WHERE extended_downline."Same Month" <> 0
AND extended_downline."Generation" <> 0
AND mcc.personal_cc_mtd__c IS NOT NULL
GROUP BY
extended_downline."Sponsor FBO ID"
,extended_downline."Sponsor Name"
,mcc.processing_year__c
,mcc.processing_month__c
,mcc.personal_cc_mtd__c
,extended_downline."Same Month"
ORDER BY "Personal CC" DESC LIMIT 20
答案 0 :(得分:0)
您可以使用Order By ColumnPosition
例如:
Order By 4 desc