Hive 从 Greenplum SQL 迁移日期格式

发布于 2025-01-16 11:20:42 字数 332 浏览 3 评论 0原文

我正在寻求帮助将下面的 sql 查询转换为 hive 支持的日期格式。请协助。

GP:SQL

select to_date('19800302000000','yyyymmddhh24miss') date_of_birth

GP 输出:1980-03-02

GP 查询:

extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss'))) age

我们在 hive 中寻找类似的内容。请帮助我们。

I am looking for help to convert below sql query into hive supported date format. kindly assist.

GP: SQL

select to_date('19800302000000','yyyymmddhh24miss') date_of_birth

GP Output : 1980-03-02

GP query :

extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss'))) age

we are looking similar out in hive. please help us.

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

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

发布评论

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

评论(1

临走之时 2025-01-23 11:20:42

对于 select to_date('19800302000000','yyyymmddhh24miss') 使用此
选择 from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS'))

如果您不需要时间部分,请使用此
选择 to_date(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS')))

对于 extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss')))age

使用以下代码。它应该给出昨天和出生日期之间的年份差异。

select 
year(current_date() - interval 1 day ) - 
year(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS'))) age

For select to_date('19800302000000','yyyymmddhh24miss') use this
select from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS')).

If you dont want time part, use this
select to_date(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS'))).

For extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss'))) age

use below code. it should give difference of years between yesterday and DOB.

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