如何将字符串'yyyymm'
计算到字符串'yyyymm -1'
例如:在T-SQL中将'201401'
计算为'201312'
?
答案 0 :(得分:0)
SQL> select * from t_flag
2 /
EMP_NAME EMP_NO DEPT
-------------------------------------------------- --------- --------------------
ROBI 1 AGRO
ROBI 1 AGRO
BORIS 2 IT
SID 3 VET
BORIS 2 IT
select t_flag.*,
(case when row_number() over (partition by emp_name,emp_no,dept order by emp_name) = 1
then 0 else 1
end) as GroupFlag
from t_flag
SQL> /
EMP_NAME EMP_NO DEPT GROUPFLAG
-------------------------------------------------- --------- -------------------- ---------
BORIS 2 IT 0
BORIS 2 IT 1
ROBI 1 AGRO 0
ROBI 1 AGRO 1
SID 3 VET 0