在 python 和 sql 中对日期进行切片
我有一个包含几列的数据框,其中一列是“account_close_date”。数据如下
column_1column_2account_close_date | 所示 | 34564 |
---|---|---|
abcde | 12345 | 2022-01-01 |
fghij | 45544 | |
klmno | 12378 | |
asdff | 2020-08-05 | 01235 |
ploif | 93458 | 2021-12-31 |
asdhj | 2021-10-20 | : |
空“account_close_date”列中的值表示该帐户仍处于打开状态。
我需要对 2021 年 10 月 31 日之后的所有值进行切片。为了在 python 中做到这一点,我正在执行以下操作:
df[~(df['account_closed_date'] >= '2021-11-01')]
但是,当我尝试在 SQL 中执行相同的切片时,我得到了不同的结果。我在 SQL 中进行的切片是:
WHERE account_closed_date < CAST('2021-11-01' as DATE) OR account_closed_date IS NULL
我应该如何更改 SQL 中的编码以获得相同的结果?
非常感谢 问候
I have a dataframe that has several columns and one of them is "account_closed_date". The data looks like:
column_1 | column_2 | account_closed_date |
---|---|---|
abcde | 12345 | 2022-01-01 |
fghij | 45544 | |
klmno | 12378 | |
asdff | 34564 | 2020-08-05 |
ploif | 93458 | 2021-12-31 |
asdhj | 01235 | 2021-10-20 |
Empty values in column "account_closed_date" mean that the account is still open.
I need to slice all values that came after 2021-10-31. To do that in python I'm doing the following:
df[~(df['account_closed_date'] >= '2021-11-01')]
However, when I try to do the same slicing in SQL I obtain a different result. The slicing that I'm doing in SQL is:
WHERE account_closed_date < CAST('2021-11-01' as DATE) OR account_closed_date IS NULL
How should I change my coding in SQL to obtain the same result?
Thank you very much
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论