Learning Notes 2022/10/17 DAY4

一、Work Summary

今日依旧是熟悉数据库,熟悉大概了20张表

二、Individual learning

1、MaxCompute 日期数据格式转换

STRING转换为TIMESTAMP(格式为yyyy-mm-dd hh:mi:ss.ff3

使用CAST函数

限制:输入的STRING类型数据的格式至少要满足yyyy-mm-dd hh:mi:ss要求。

--返回2009-07-01 16:09:00.000。
select cast("2009-07-01 16:09:00" as timestamp)

STRING转换为DATETIME

使用CAST函数和TO_DATE函数

限制:

使用CAST函数时,输入的STRING类型数据的格式必须要满足yyyy-mm-dd hh:mi:ss要求。

使用TO_DATE函数时,需要指定format参数的取值为yyyy-mm-dd hh:mi:ss

--返回2009-07-01 16:09:00
select cast('2009-07-01 16:09:00' as DATETIME);
select TO_DATE('2009-07-01 16:09:00','yyyy-mm-dd hh:mi:ss');

TIMESTAMP(格式为yyyy-mm-dd hh:mi:ss.ff3)转换为STRING

使用CAST函数和TO_STRING函数

--返回2009-07-01 16:09:00。
select(cast(cast('2009-07-01 16:09:00' as timestamp) as string));
select to_char(cast('2009-07-01 16:09:00' as timestamp),'yyyy-mm-dd hh:mi:ss');

TIMESTAMP转换为DATETIME

使用CAST函数和TO_DATE函数

限制:使用TO_DATE函数时,需要指定format参数的取值为yyyy-mm-dd hh:mi:ss

--返回2009-07-01 16:09:00。
select cast(cast('2009-07-01 16:09:00' as timestamp) as datetime);
select TO_DATE(cast('2009-07-01 16:09:00' as timestamp),'YYYY-MM-DD HH:MI:SS');

DATETIME转换为TIMESTAMP

使用cast()函数

--返回2021-10-14 10:21:47.939
select cast(getdate() as timestamp);

DATETIME转换为STRING

使用cast()函数和to_char()函数

--返回2021-10-14 10:21:47。
select cast(getdate() as string);
--返回2021-10-14 10:21:47。
select to_char (getdate(),'yyyy-mm-dd hh:mi:ss');
--返回2021-10-14。
select to_char (getdate(),'yyyy-mm-dd');
--返回2021。
select to_char (getdate(),'yyyy');

2、数据迁移、实现结巴中文分词参考官方文档

https://www.alibabacloud.com/help/zh/maxcompute/latest/use-a-pyodps-node-to-segment-chinese-text-based-on-jieba


There is no royal road to size, there is no end to learning work boat.
欢迎各位朋友指导、交流、评论!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值