我正在尝试选择一行,这些行具有(某些指定的)与前一行相同的值。
我可以选择以下内容:
SELECT dpr_ts
, dpr_open
, dpr_volume
, LAG(dpr_open, 1, 0) over(ORDER BY dpr_ts) AS po
, LAG(dpr_close, 1, 0) over(ORDER BY dpr_ts) AS pc
, LAG(dpr_volume, 1, 0) over(ORDER BY dpr_ts) AS pv
FROM dpr
ORDER BY dpr_ts;
如何在where子句中指定只显示重复项?
我的意思是我想要一些像这样的东西,但只是为了让你知道我正在尝试的东西:
SELECT dpr_ts
, dpr_open
, dpr_volume
, LAG(dpr_open, 1, 0) over(ORDER BY dpr_ts) AS po
where po = dpr_volume;
由于 问候
答案 0 :(得分:3)
我认为你想要的是:
select *
from (
select dpr_ts
, dpr_open
, dpr_volume
, LAG(dpr_open, 1, 0) over(ORDER BY dpr_ts) AS po
from dpr
order by drp_ts
) x
where x.po = x.dpr_volume