HIVE場景題之交差並集

2021-09-27 12:30:28 字數 1895 閱讀 6385

1.4.1使用hive求出兩個資料集的差集

資料t1表: id name

1zs2ls

t2表: id name

1 zs

3 ww

結果如下:

id name

2 ls

3 ww

create table diff_t1( id string,

name string

)row format delimited fields terminated by 』 』

;load data local inpath 『/hivedata/diff_t1.txt』 overwrite into table diff_t1;

create table diff_t2( id string,

name string

)row format delimited fields terminated by 』 』

;load data local inpath 『/hivedata/diff_t2.txt』 overwrite into table diff_t2;

select t1.id as id, t1.name as name from diff_t1 t1

left join diff_t2 t2 on t1.id=t2.id

where t2.id is null union

select

t2.id as id, t2.name as name from diff_t1 t1

right join diff_t2 t2 on t1.id=t2.id

where t1.id is null

;1.4.2兩個表a 和b ,均有key 和value 兩個字段,寫乙個sql語句,將b表中的value值置成a表中相同key值對應的value值

1.4.3有使用者表user(uid,name)以及黑名單表banuser(uid)

1、用left join方式寫sql查出所有不在黑名單的使用者資訊

2、用not exists方式寫sql查出所有不在黑名單的使用者資訊

select u.id, u.name from u

left join banuser b on u.id=b.id

where b.id is null

;2、select u.id, u.name from u

where not exists (select 1 from banuser b where u.id=b.id)

;

STL之交集 並集 差集

stl對集合操作有標準的演算法,有沒有用過呢?使用它們的時候有需要注意什麼?例子程式?如果沒接觸過,請看這裡的簡單介紹 交集set intersection 並集set union 差集set difference 對稱差集set symeetric difference。針對這裡提及的四個集合運算...

並查集簡單題

題目傳送 poj 1611 the suspects ac include include include include include include include include include include include include include include define l...

並查集 題1

問題描述 今天是ignatius的生日。他邀請很多朋友。現在是晚餐時間。ignatius想知道他至少需要多少張桌子。你必須注意到,並不是所有的朋友都認識對方,所有的朋友都不想留在陌生人身上。這個問題的乙個重要規則是,如果我告訴你a知道b,b知道c,這意味著a,b,c彼此認識,所以他們可以留在乙個表中...