提取命令在mysql中返回null ..请有什么建议吗?

发布于 2025-01-22 11:33:15 字数 230 浏览 2 评论 0原文

我正在尝试从订单_date从名为warehouse.big_w_orders中获取年。 order_date包含一个日期格式,例如1/1/2019,但数据类型是文本。当我在下面编写查询时,只是返回“ null'而不是2019年。我尝试使用铸件将数据类型更改为迄今为止甚至浮动,但也没有起作用。

从warehouse.big_w_orders中选择提取物(从order_date的年);

有人可以在这里帮我吗?先感谢您!

I'm trying to pull year from order_Date from the table called warehouse.big_w_orders. order_date contains a date format such as 1/1/2019 but the data type is text. When I write the query below it just returns 'null' not 2019. I tried to use CAST fuction to change the data type to date or even float but it didn't work either.

SELECT extract(year from order_date) FROM warehouse.big_w_orders;

Could someone please help me out here? Thank you in advance!

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

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

发布评论

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

评论(1

白首有我共你 2025-01-29 11:33:15

如您所说,order_date的数据类型是文本。因此,从技术上讲,您不能从文本中提取年。您需要先将文本转换为日期。

尝试以下操作:

SELECT extract(year from to_date(order_date,'DD/MM/YYYY')) FROM warehouse.big_w_orders;

As you said, the data type of order_date is text. So technically, you cannot extract year from text. You need to convert your text to a date first.

Try this:

SELECT extract(year from to_date(order_date,'DD/MM/YYYY')) FROM warehouse.big_w_orders;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文