将公式应用于列时使用 CASE 的 sql 查询出错

Error in sql query using CASE when applying formula to the column

我必须在交易 table 的金额栏中应用费用。如果金额大于 5000 那么我必须对 每笔交易 应用 17.5 并在最后取和。如果金额小于 5000,那么我必须在金额上应用 百分比公式 ,然后在最后取它的总和。以下是我的查询,但出现以下异常:

SELECT 
        CASE  
        When tran_amount_req >= 5000 Then sum(17.5) 
        When tran_amount_req < 5000 Then sum(((tran_amount_req/100) * 0.35)/100) 
        End as MyPercent
        from gstl_trans_temp
        where (message_type_mapping = '0220') and card_type ='GEIDP1'

gstl_trans_temp.tran_amount_req 在 select 列表中无效,因为它未包含在聚合函数或 GROUP BY 子句中。

请帮忙,提前致谢。

是否要进行如下条件聚合?

SELECT sum(CASE When tran_amount_req >= 5000 then 17.5 
                else ((tran_amount_req/100) * 0.35)/100 
           End) as MyPercent
 from gstl_trans_temp
where message_type_mapping = '0220' 
  and card_type ='GEIDP1'