由于安全原因我删除了表名.Sorry
答案 0 :(得分:0)
我认为您需要添加partition by
:
SELECT pgm_id, pml.period_id, medi_cov_lives,
LAG(medi_cov_lives, 1, 0)
OVER (PARTITION BY pgm_id ORDER BY pml.pgm_id, pml.period_id
) AS pre_medi_cov_lives
FROM <table> pml;
答案 1 :(得分:0)
您需要指定lag
分别处理每个pgm_id
,并使用partition by
子句:
CREATE OR REPLACE FORCE VIEW HCRS.PGM_MEDI_LIVES_V
(
PGM_ID,
PERIOD_ID,
MEDI_COV_LIVES,
PREV_MEDI_COV_LIVES
)
AS
SELECT
pgm_id,
pml.period_id,
medi_cov_lives,
LAG (medi_cov_lives, 1, 0)
OVER (PARTITION BY pml.pgm_id ORDER BY pml.period_id)
AS pre_medi_cov_lives
FROM PGM_MEDI_LIVES pml;