04具體分析

2021-09-26 05:51:31 字數 3546 閱讀 9386

思路:

使用order by按照views欄位做乙個全域性排序即可,同時我們設定只顯示前10條。

**:select videoid, uploader, age, category, length, views, rate, ratings, comments

from gulivideo_orc order by views desc limit 10;

思路:

(2)我們需要按照類別group by聚合,然後count組內的videoid個數即可。

(4)最後按照熱度排序,顯示前10條。

**:select category_name as category, count(t1.videoid) as hot from

(select videoid,category_name from

gulivideo_orc lateral view explode(category) t_catetory as category_name) t1

group by t1.category_name order by hot desc limit 10;

思路:

(2)把這20條資訊中的category**出來(列轉行)

**:select category_name as category,count(t2.videoid) as hot_with_views from

(select videoid, category_name from

(select * from gulivideo_orc order by views desc limit 20) t1

lateral view explode(category) t_catetory as category_name) t2

group by category_name order by hot_with_views desc;

思路:

select * from gulivideo_orc order by views desc limit 50;

select explode(relatedid) as videoid from t1;

(select distinct(t2.videoid), t3.category from t2 inner join

gulivideo_orc t3 on t2.videoid = t3.videoid) t4 lateral view explode(category) t_catetory as category_name;

**: select category_name as category,count(t5.videoid) as hot from

(select videoid,category_name from

(select distinct(t2.videoid),t3.category from

(select explode(relatedid) as videoid from

(elect * from gulivideo_orc order by views desc limit 50) t1) t2

inner join

gulivideo_orc t3 on t2.videoid = t3.videoid) t4 lateral view explode(category) t_catetory as category_name) t5

group by category_name order by hot desc;

思路:

(2)向category展開的表中插入資料。

**: 建立表類別表:

create table gulivideo_category(

videoid string,uploader string,age int,categoryid string,length int,

views int,rate float,ratings int,comments int,relatedid array)

row format delimited

fields terminated by "\t"

collection items terminated by "&"

stored as orc;

向類別表中插入資料:

insert into table gulivideo_category

select videoid,uploader,age,categoryid,

length,views,rate,ratings,comments,relatedid

from

gulivideo_orc lateral view explode(category) catetory as categoryid;

統計music類別的top10(也可以統計其他)

select videoid, views from gulivideo_category

where categoryid = "music" order by views desc limit 10;

思路:

(2)按照ratings排序即可

**:select videoid,views,ratings from gulivideo_category

where categoryid = "music" order by ratings desc limit 10;

思路:

select * from gulivideo_user_orc order by videos desc limit 10;

(2)通過uploader欄位與gulivideo_orc表進行join,得到的資訊按照views**次數進行排序即可。

**: select t2.videoid,t2.views,t2.ratings,t1.videos,t1.friends

from (select * from gulivideo_user_orc order by videos desc limit 10) t1

join gulivideo_orc t2

on t1.uploader = t2.uploader order by views desc limit 20;

思路:

(1)先得到categoryid展開的表資料

(2)子查詢按照categoryid進行分割槽,然後分區內排序,並生成遞增數字,該遞增數字這一列起名為rank列

(3)通過子查詢產生的臨時表,查詢rank值小於等於10的資料行即可。

**: select t1.* from (select videoid,categoryid,views,

row_number() over(partition by categoryid order by views desc)

rank from gulivideo_category) t1 where rank <= 10;

Gnutella協議具體分析

術語與網路管理 sevent 乙個加入gnutella網路的程式稱為servent,是 server 和 client 的縮寫。peer node 和 host 也有著類似的意思,但更強 調的是乙個參與者而不是乙個程式。當乙個servent有乙個確切的client或server身份,可能會使用cli...

while迴圈具體分析?

while實現0加到100的計算?break為跳出當前迴圈,其實break還有乙個作用就是可以跳到指定的地方。注意 不可以使用千萬級以上的迴圈,如i 10000000 while是迴圈效率最高的,雖然for是使用最多的,但for也只是寫法簡單而已。總結 break 跳出條件迴圈外,不再進入迴圈。co...

9 4 具體的物件型別

9.4 具體的物件型別 物件導向程式設計中的最重要的結構,就是類的宣告。它的價值體現用 f 寫的庫,可以在 c 中使用,因為從 c 中引用f 宣告的類時,看起來就像普通的類。從概念上講,類有一點像帶成員的記錄,因為,它們把值儲存在字段中,並提供成員進行訪問 類還有另外的功能,在 f 中,出現下列情況...