---
title: "hive初试"
author: "zhanjun"
date: "2016-02-29T08:35:35Z"
tags: []
categories: ["编程语言"]
slug: "hive"
draft: false
lastmod: "2016-03-01T09:54:47Z"
id: 2279404
url: "https://zhanjun.iteye.com/blog/2279404"
---

1：搭建hadoop和hive，mysql的环境，过程截图。

 

2：利用上节课的数据，建表并导入数据。

3：最热门的查询词排行 top10  
4：用户查询排行 top10  
5：搜索结果排名第1，但是点击次序排在第2的数据有多少?

 

2：利用上节课的数据，建表并导入数据。

数据格式说明：  
访问时间\\t用户ID\\t\[查询词]\\t该URL在返回结果中的排名\\t用户点击的顺序号\\t用户点击的URL  
其中，用户ID是根据用户使用浏览器访问搜索引擎时的Cookie信息自动赋值，即同一次使用浏览器输入的不同查询对应同一个用户ID。

CREATE EXTERNAL TABLE sg\_table(  
  last\_update string,  
  col\_a string,  
  col\_b string,  
  col\_c string,  
  col\_d string,  
  col\_e string,  
  col\_f string,  
  col\_g string,  
  col\_h string,  
  col\_i string,  
  col\_j string)  
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\t'  
location '/hadoop/dw/sogoutest';  
hadoop put sogout.txt /hadoop/dw/sogoutest

 

3：最热门的查询词排行 top10

select col\_b ,count(col\_b) as top10 from sg\_table group by col\_b  order by top10  desc limit 10 ;

4：用户查询排行 top10

select col\_a ,count(col\_a) as top10 from sg\_table group by col\_a  order by top10  desc limit 10 ;

5：搜索结果排名第1，但是点击次序排在第2的数据有多少?

select col\_b , count(col\_b) as top1  from sg\_table where col\_i=2 group by col\_b order by top1 desc limit 1;