我正在尝试更新,如果员工有终止日期,则将下一个加入日期更新为终止日期 - 在 postgresql 中为 1 天。不应更新第一个 Join_date。
示例:
EmpID | Dept_No | Join_Date | termination_date | ID |
---|---|---|---|---|
1001 | 11 | 2020-01-01 | 2020-02-01 | 183 |
1001 | 12 | 2020-02-02 | 2020-04-01 | 182 |
1001 | 11 | 2020-04-02 | 186 |
下面是我想要得到的输出。
Dept_No | 加入日期 | 终止日期 |
---|---|---|
11 | 2020-01-01 | 2020-02-01 |
12 | 2020-02-01 | 2020-04-01 |
11 | 2020-04-01 |
以下是我目前所拥有的,
UPDATE employee e
SET Join_Date =
((termination_date) -INTERVAL '1 DAY')
WHERE termination_date IS NOT NULL;
但我不确定如何添加以下条件,
有人可以建议如何添加吗?提前致谢。
答案 0 :(得分:1)
在 file.truncate
语句中使用 def file_redact(file_name: str):
line_to_replace = int(input('Enter the line to replace (starting from 1): '))
f = open(file_name, 'r+')
file_data = f.readlines()
file_data[line_to_replace - 1] = input('Write a new line:\n') + '\n'
f.truncate(0)
f.seek(0)
f.writelines(file_data)
f.close()
file_redact("test.txt")
:
EXISTS
参见demo。
结果:
empid | dept_no | join_date | termination_date | id |
---|---|---|---|---|
1001 | 11 | 2020-01-01 | 2020-02-01 | 183 |
1001 | 12 | 2020-02-01 | 2020-04-01 | 182 |
1001 | 11 | 2020-04-01 | null | 186 |