Hive 中各種關(guān)鍵詞的排序

//五種子句是有嚴(yán)格順序的:

where → group by → having → order by → limit

//where和having的區(qū)別:

//where是先過濾再分組(對原始數(shù)據(jù)過濾),where限定聚合函數(shù)

hive> select count(*),age from tea where id>18 group by age;

//having是先分組再過濾(對每個(gè)組進(jìn)行過濾,having后只能跟select中已有的列)

hive> select age,count(*) c from tea group by age having c>2;

//group by后面沒有的列,select后面也絕不能有(聚合函數(shù)除外)

hive> select ip,sum(load) as c from logs? group by ip sort by c desc limit 5;

//distinct關(guān)鍵字返回唯一不同的值(返回age和id均不相同的記錄)

hive> select distinct age,id from tea;

//hive只支持Union All,不支持Union

//hive的Union All相對sql有所不同,要求列的數(shù)量相同,并且對應(yīng)的列名也相同,但不要求類的類型相同(可能是存在隱式轉(zhuǎn)換吧)

select name,age from tea where id<80

union all

select name,age from stu where age>18;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容