1,創建表格
create table stu(name string,hobby array<string>,scores map<string,double>)
row format delimited
fields terminated by ','
collection items terminated by '-'
MAP KEYS TERMINATED BY ':';
2,匯入資料
資料:
zs,drink-eat,english:90-math:66
ls,drink-playgames-chat,english:60-math:66
w6,drink,english:80-math:66
w7,playgames,english:90-math:70
z9,drink-eat,english:90.4-math:66.5
x8,drink,english:80.3-math:66.7
load 命令匯入資料到表中
load data local inpath '/root/data' into table stu;
3,練習
查詢所有
select * from score
關系運算子
1、查詢math成績大于66的學生
select * from score where scores['math']>66
2、查詢math成績等于66的學生
select * from score where scores['math']=66
3、查詢math成績不等于90的學生
select * from score where scores['math']<>90;
4、like 查詢類似的
w開頭的資料 和s結尾的資料
select * from score where name like 'w%';
select * from score where name like '%s'
算術運算子
1、相加 語文+數學的成績和
select scores['chinese']+scores['math']from score
數學函式
1、四舍五入
select round(scores['english']) from stu where name='z9';
2、floor 丟棄
select floor(scores['math']) from stu where name='x8';
3、ceil 進一
select ceil(scores['english']) from stu where name='x8';
4、max最大值
找到數學成績最高是多少
select max(scores['math']) from stu;
5、sum
select sum(scores['math']) from stu;
6、avg平均
select avg(scores['math']) from stu;
7、列的方差
var_pop
select var_pop(scores['math']) from stu;
收集函式
1、size (陣列 或者 map)回傳集合個數
找出每個人的愛好有幾個
select name,size(hobby) from stu;
字串函式
1、length:回傳長度
select name,length(name) from stu;
2、regexp_replace(string A, string B, string C)
字串A中的B字符被C字符替代
姓名中的z被x代替:
select regexp_replace(name,'z','x') from stu;
3、trim去掉字串兩邊的空格
trim(string A):去掉A兩邊的空格
4、split(string str, string pat):按照pat分割str回傳一個陣列
5、explode(array a):把一個陣列打散為多行
其他
corr(col1, col2)
回傳兩列數值的相關系數
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/377005.html
標籤:其他
上一篇:Hadoop筆記(偽分布事搭建)
下一篇:大資料elementUI專案總結
