如果我有一个类似
的表在我的桌子上,我想比较每两个连续的行。假设employee_status是'yes',之后是'pro'。然后,我想添加另一列,并在两行中写“问题”,在其他行中写“没问题”。 喜欢,
答案 0 :(得分:0)
您可以使用lead()
/ lag()
(或与之等效的Teradata)和case
表达式:
select t.*
(case when employee_status = 'yes' and
max(employee_status) over (order by employee_no rows between 1 following and 1 following) = 'pro'
then 'problem'
when employee_status = 'pro' and
max(employee_status) over (order by employee_no rows between 1 preceding and 1 preceding) = 'yes'
then 'problem'
else 'no problem'
end) as problem_col
from t;