复制代码 代码如下:
WITH my1 AS (
SELECT *,
CASE
WHEN je > rwe THEN (je * fld)
ELSE 0
END fle,
CAST(0 AS FLOAT) tmp
FROM tb
WHERE qj = 1
UNION ALL
SELECT tb.*,
CASE
WHEN tb.je > tb.rwe THEN (tb.je - my1.fle -my1.tmp)
* tb.fld
ELSE 0
END fle,
my1.fle + my1.tmp tmp -- 用于累加前面月份的返利
FROM my1,
tb
WHERE tb.qj = my1.qj + 1
)
SELECT *
FROM my1
新闻热点
疑难解答