-1
以前的記錄,由於安全原因,我刪除表names.Sorry甲骨文:獲取基於基於週期
以前的記錄,由於安全原因,我刪除表names.Sorry甲骨文:獲取基於基於週期
我認爲你需要添加值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;
你需要指定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;
非常感謝你 –