1.unix_timestamp:返回當前或指定時間的時間戳
2.from_unixtime:將時間戳轉為日期格式select unix_timestamp();
select unix_timestamp(
'2008-08-08 08:08:08'
);
3.current_date:當前日期select from_unixtime(
1218182888);
select from_unixtime(unix_timestamp())
;
4.current_timestamp:當前的日期加時間select
current_date()
;
5.to_date:抽取日期部分select
current_timestamp()
;
6.year:獲取年select to_date(
'2008-08-08 08:08:08');
select to_date(
current_timestamp()
);
7.month:獲取月select
year
(current_timestamp()
);
8.day:獲取日select
month
(current_timestamp()
);
9.hour:獲取時select
day(
current_timestamp()
);
10.minute:獲取分select
hour
(current_timestamp()
);
11.second:獲取秒select
minute
(current_timestamp()
);
12.weekofyear:當前時間是一年中的第幾周select
second
(current_timestamp()
);
13.dayofmonth:當前時間是乙個月中的第幾天select weekofyear(
current_timestamp()
);select weekofyear(
'2020-01-08'
);
14.months_between: 兩個日期間的月份select dayofmonth(
current_timestamp()
);select dayofmonth(
'2020-01-08'
);
15.add_months:日期加減月select months_between(
'2020-07-29'
,'2020-06-28'
);
16.datediff:兩個日期相差的天數select add_months(
'2020-06-28',1
);
17.date_add:日期加天數select datediff(
'2019-03-01'
,'2019-02-01');
select datediff(
'2020-03-01'
,'2020-02-01'
);
18.date_sub:日期減天數select date_add(
'2019-02-28',1
);select date_add(
'2020-02-28',1
);
19.last_day:日期的當月的最後一天select date_sub(
'2019-03-01',1
);select date_sub(
'2020-03-01',1
);
20.date_format() :格式化日期 日期格式:『yyyy-mm-dd hh:mm:ss』select last_day(
'2020-02-28');
select last_day(
'2019-02-28'
);
1.round: 四捨五入select date_format(
'2008-08-08 08:08:08'
,'yyyy-mm-dd hh:mm:ss'
);
2.ceil: 向上取整select
round
(4.5);
select
round(-
4.4)
;
3.floor: 向下取整 select floor(4.5);select ceil(
4.01);
select ceil(
4.0)
;
1.upper: 轉大寫select floor(
4.99);
select ceil(
5.0)
;
2.lower: 轉小寫select upper(
'abcdefg'
);
3.length: 長度select lower(
'abcdefg'
);
4.trim: 前後去空格select length(
'abcdefg'
);
5.lpad: 向左補齊,到指定長度select length(
' abcdefg ');
select length(trim(
' abcdefg '))
;
6.rpad: 向右補齊,到指定長度select lpad(
'abc',11
,'*'
);
7.substring: 剪下字串select rpad(
'abc',11
,'*'
);
8.regexp_replace:使用正規表示式匹配目標字串,匹配成功後替換!select substring(
'abcdefg',1
,3);
select rpad(substring(
'13843838438',1
,3),
11,'*')
;
1.size: 集合中元素的個數select regexp_replace(
'100-200'
,'(\\d+)'
,'num');
select regexp_replace(
'abc d e f'
,' ',''
);
2.map_keys: 返回map中的key
3.map_values: 返回map中的value
4.array_contains: 判斷array中是否包含某個元素select size(friends)
,map_keys(children)
,map_values(children)
from person;
5.sort_array: 將array中的元素排序select array_contains(friends,
'lili'
)from person;
select sort_array(split(
'1,3,4,5,2,6,9'
,','))
;select sort_array(split(
'a,d,g,b,c,f,e'
,','))
;
hive中常用的函式
獲取當前時間戳 hive select unix timestamp ok1605712071獲取指定日期時間戳 hive select unix timestamp 2020 01 01 00 00 00 ok1577836800獲取指定格式的時間戳 hive select unix timest...
hive中常見的關於日期的函式 (整理)
unix timestamp 返回當前或指定時間的時間戳 from unixtime 將時間戳轉為日期格式 current date 當前日期 current timestamp 當前的日期加時間 to date 抽取日期部分 year 獲取年 month 獲取月 day 獲取日 hour 獲取時 ...
Hive中常用SQL梳理
注意 hive子查詢需要起別名!先groupby後取第一條 方法1 遇到這麼乙個需求,輸入資料為乙個id對應多個name,要求輸出資料為id是唯一的,name隨便取乙個就可以。select a.from select row number over partition by id order by ...