Home [Hive] Timestamp 쿼리 정리
Post
Cancel

[Hive] Timestamp 쿼리 정리

TIMESTAMP로 변환

1
2
3
4
SELECT CAST(UNIX_TIMESTAMP("2021-03-25T15:32:22+09:00", "yyyy-MM-dd'T'HH:mm:ss") * 1000 AS TIMESTAMP)

-- Query Result
2021-03-25 15:32:22.0

HH 추출

1
SELECT CAST(DATE_FORMAT(request_timestamp, 'HH') AS INT) AS hh

STRING > TIMESTAMP

1
SELECT FROM_UNIXTIME(TO_UNIX_TIMESTAMP(column_name, 'yyyy-MM-dd HH:mm:ss'))

DIFF

1
SELECT DATEDIFF(FROM_UNIXTIME(TO_UNIX_TIMESTAMP(column_name, 'yyyy-MM-dd HH:mm:ss')), FROM_UNIXTIME(TO_UNIX_TIMESTAMP(column_name, 'yyyy-MM-dd HH:mm:ss'))) AS diff_days
This post is licensed under CC BY 4.0 by the author.

[Hive] External 테이블 생성 쿼리

[Jekyll] Chirpy Theme Favicon, Avatar 세팅