在 python 和 sql 中对日期进行切片

发布于 2025-01-16 13:57:15 字数 969 浏览 8 评论 0原文

我有一个包含几列的数据框,其中一列是“account_close_date”。数据如下

column_1column_2account_close_date所示34564
abcde123452022-01-01
fghij45544
klmno12378
asdff2020-08-0501235
ploif934582021-12-31
asdhj2021-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_1column_2account_closed_date
abcde123452022-01-01
fghij45544
klmno12378
asdff345642020-08-05
ploif934582021-12-31
asdhj012352021-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文