A person displays a row of records, with one-time benefits and regular benefits on the same row.
A query statement is sent as follows, which is very long. Don't be frightened, there are not many things used, the essence is grouping, aggregation
SELECT C.*, (C.AAE019OLD + C.AAE019CE) AAE019NEW FROM (SELECT T.AAZ257, T.AAC001, T.AAB001, T.AAC147, T.AAC003, T.AAC004, T.AAC012, T.AAA027, T.AAC006, T.AAC007, T.AAC055, T.AIC162, T.AIC161, T.AAC020, T.BIC215, T.AAE200, T.AAE210, T.AAC081, T.AAC085, T.AAC064, T.AAC014, T.AAC015, (SELECT SUM(A.AAE019) FROM AC61 A, AA17 B WHERE A.AAA036 = B.AAA036 AND A.AAZ257 = T.AAZ257 AND B.BAZ057 = 100000 AND A.AAE041 <= (CASE WHEN T.AAE210 > 201701 THEN T.AAE210 ELSE 201701 END) AND A.AAE042 >= (CASE WHEN T.AAE210 > 201701 THEN T.AAE210 ELSE 201701 END)) AAE019OLD, decode(t.dqflag, '1', SUM(T.AAE188)) AAE019CE, decode(t.dqflag, '0', SUM(T.AAE188)) aae019ycxce FROM T_YLZCTZ T WHERE T.BIC226 = 1000000000000463 GROUP BY T.AAZ257, T.AAC001, T.AAB001, T.AAC147, T.AAC003, T.AAC004, T.AAC012, T.AAA027, T.AAC006, T.AAC007, T.AAC055, T.AIC162, T.AIC161, T.AAC020, T.BIC215, T.AAE200, T.AAE210, T.AAC081, T.AAC085, T.AAC064, T.AAC014, T.AAC015, t.dqflag) C
key point:
decode(t.dqflag, '1', SUM(T.AAE188)) AAE019CE,
Except for the items following the group by statement, all items that appear in the query must be aggregate functions.
Remove t.dqflag after group by,
The query becomes sum((case when t.dqflag='1' then 0 else t.aae188 end)) AAE019CE,
When periodic, only sum non-1
When non-periodic, only sum non-zero.