减法天数(黑斑羚)

发布于 2025-01-12 19:40:59 字数 195 浏览 1 评论 0原文

您能告诉我如何显示“日期”减去今天日期两天的行吗?以及如何更改字符串的数据类型。 “日期”列采用 YYYYMMDD 格式。

为什么这个查询不起作用?

select * from table where 'date'= cast(subdate(current_date(), 2 days) as string)

Can you please tell me how to display lines where 'date' minus two days from today's date. And how then to change the data type of string. The 'date' column is in YYYYMMDD format.

Why is this query not working?

select * from table where 'date'= cast(subdate(current_date(), 2 days) as string)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2025-01-19 19:40:59

使用下面的

select * from table where `date`=  from_timestamp(now() - interval 2 days,'yyyyMMdd') 

from_timestamp(timestamp_data, 'yyyyMMdd') - 这会将日期转换为所需的字符串格式。
-interval 2 days - 这会将日期时间恢复到系统日期之前的 2 天。

use below

select * from table where `date`=  from_timestamp(now() - interval 2 days,'yyyyMMdd') 

from_timestamp(timestamp_data, 'yyyyMMdd') - This converts a date to a desired string format.
-interval 2 days - This takes date time back to 2days before system date.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文