Oracle :基于期间的先前记录获取价值
Posted
技术标签:
【中文标题】Oracle :基于期间的先前记录获取价值【英文标题】:Oracle :Get Value based on a previous record based on period 【发布时间】:2015-05-22 12:18:59 【问题描述】:出于安全原因,我删除了表名。对不起
【问题讨论】:
【参考方案1】:您需要指定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;
【讨论】:
【参考方案2】:我觉得你需要加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;
【讨论】:
以上是关于Oracle :基于期间的先前记录获取价值的主要内容,如果未能解决你的问题,请参考以下文章
GraphQL - 如何在查询多个突变期间检索先前突变的 id