开窗函数over()
ran()
日期函数
1. date_add()加减day
date_format(date_add(current_date,-10),'yyyy-MM-dd HH:mm:ss')
2. UNIX_TIMESTAMP()加减秒
from_unixtime(UNIX_TIMESTAMP(call_time,'yyyy-MM-dd HH:mm:ss.SSSSS')+duration, 'yyyy-MM-dd HH:mm:ss.S')
3. add_months()加减月
add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd HH:mm:ss'), -1)
trunc(add_months(current_date,-1) ,'MM')
4. current_date()当前时间
yyyy-MM-dd的格式
5.获取年月日时分秒
second(time) as second
minute(time) as minute
hour(day) as hour
day(day) as day
month(day) as month
year(day)
建表
CREATE TABLE
Drop table if exists <库名>.<表名>;
create table if not exists <库名>.<表名>(
id int comment’注解’,
name string comment’注解’,
age int comment’注解’,
likes ARRAY<string> comment’注解’,
address MAP<string,string> comment’注解’,
Sex_ID string comment’注解’,
Dt_ID string
) comment’表名注解’
partitioned by (sex string comment’注解’,
dt string comment’注解’)
row format delimited
NULL DEFINED AS ''
fields terminated by ','
collection items terminated by '-'
MAP keys terminated by ':'
lines terminated by '\n'
stored as ORC;
CREATE TEMPORARY TABLE
Drop table if exists <库名>.<表名>;
create TEMPORARY table if not exists <库名>.<表名> stored as ORC as (
id int comment’注解’,
name string comment’注解’,
age int comment’注解’,
likes ARRAY<string> comment’注解’,
address MAP<string,string> comment’注解’,
Sex_ID string comment’注解’,
Dt_ID string
) comment’表名注解’
partitioned by (sex string comment’注解’,
dt string comment’注解’)
row format delimited
NULL DEFINED AS ''
fields terminated by ','
collection items terminated by '-'
MAP keys terminated by ':'
lines terminated by '\n'
stored as ORC;
show - 分区,表结构等.
show create table
show partitions table
desc table