Hive 练习 简单任务处理
1、2018年4月份的用户数、订单量、销量、GMV (不局限与这些统计量,你也可以自己想一些)
-- -- -- 2018年4月份的用户数量
select
count(a.user_id) as user_nums
from
(
select
user_id
from
app_jypt_m04_ord_det_di
where
dt >= '2018-04-01'
and sale_ord_dt <= '2018-04-30'
and sale_ord_dt >= '2018-04-01'
group by
user_id
)
a;
-- 2018年4月份的订单量
select
count(a.sale_ord_id) as sale_nums
from
(
select
sale_ord_id
from
app_jypt_m04_ord_det_di
where
dt >= '2018-04-01'
and sale_ord_dt <= '2018-04-30'
and sale_ord_dt >= '2018-04-01'
group by
sale_ord_id
)
a;
-- -- 2018年4月份的销量
select
sum(COALESCE(sale_qtty, 0)) as xiaoliang
from
app_jypt_m04_ord_det_di
where
dt >= '2018-04-01'
and sale_ord_dt <= '2018-04-30'
and sale_ord_dt >= '2018-04-01';
-- -- -- 2018年4月份的销售额GMV
-- user_payable_pay_amount 用户应付金额
select
sum(user_payable_pay_amount) as xiaoshoujine
from
app_jypt_m04_ord_det_di
where
dt >= '2018-04-01'
and sale_ord_dt <= '2018-04-30'
and sale_ord_dt >= '2018-04-01';
PS:
- 订单数就是卖了几单 ;
- 销量就是卖了多少件,一个订单中可能卖出一件或多件;
- GMV: Gross Merchandise Volume,是成交总额(一定时间段内)的意思。
- 在电商网站定义里面是网站成交金额。这个实际指的是拍下订单金额, 包含付款和未付款的部分。
2、上述这些变化量相对3月份的变化
3、计算2018年4月1号的新用户数量(之前半年未购买的用户为新用户)
-- 计算2018年4月1号的新用户数量(之前半年未购买的用户为新用户)
-- 首先找出4月1号的用户的xxx,然后统计半年内有过购买记录的用户yyy。 -- select distinct user_id as xxx from gdm_m04_ord_det_sum where dt>='2018-04-01' and sale_ord_dt='2018-04-01';
-- select distinct user_id as yyy from gdm_m04_ord_det_sum where dt>='2017-10-01' and sale_ord_dt<='2018-03-31' and sale_ord_dt>='2017-10-01'; -- 用xxx-yyy,然后count()计算数量; -- 两种方法,一种用not in ,一种用not exists -- not in 方法
select distinct user_id from gdm_m04_ord_det_sum
where user_id not in (select distinct user_id from gdm_m04_ord_det_sum where dt>='2017-10-01' and sale_ord_dt<='2018-03-31' and sale_ord_dt>='2017-10-01'); -- not exists 方法
select distinct user_id from gdm_m04_ord_det_sum where dt>='2018-04-01' and sale_ord_dt='2018-04-01' where not exists (select distinct user_id from gdm_m04_ord_det_sum where dt>='2017-10-01' and sale_ord_dt<='2018-03-31' and sale_ord_dt>='2017-10-01' where gdm_m04_ord_det_sum.user_id=gdm_m04_ord_det_sum.user_id); -- 另一种 left outer join 这样效率更高 语法有问题?? select distinct user_id from gdm_m04_ord_det_sum where dt>='2018-04-01' and sale_ord_dt='2018-04-01' a left outer join (select distinct user_id from gdm_m04_ord_det_sum where dt>='2017-10-01' and sale_ord_dt<='2018-03-31' and sale_ord_dt>='2017-10-01' b) on a.user_id=b.user_id where b.user_id is null;
正确方法:
select
count(a.id1) as user_new_nums
from
(
select distinct
user_id as id1
from
app_jypt_m04_ord_det_di
where
dt >= '2018-04-01'
and sale_ord_dt = '2018-04-01'
)
a
left outer join
(
select distinct
user_id as id2
from
app_jypt_m04_ord_det_di
where
dt >= '2017-10-01'
and sale_ord_dt <= '2018-03-31'
and sale_ord_dt >= '2017-10-01'
)
b
on
a.id1 = b.id2
where
b.id2 is null;
Hive 练习 简单任务处理的更多相关文章
- Hive 的简单使用及调优参考文档
Hive 的简单使用及调优参考文档 HIVE的使用 命令行界面 使用一下命令查看hive的命令行页面, hive --help --service cli 简化命令为hive –h 会输出下面的这 ...
- [转]Hive:简单查询不启用Mapreduce job而启用Fetch task
转自:http://www.iteblog.com/archives/831 如果你想查询某个表的某一列,Hive默认是会启用MapReduce Job来完成这个任务,如下: hive> SEL ...
- hive中简单介绍分区表
所介绍内容基本上是翻译官方文档,比较肤浅,如有错误,请指正! hive中创建分区表没有什么复杂的分区类型(范围分区.列表分区.hash分区.混合分区等).分区列也不是表中的一个实际的字段,而是一个或者 ...
- [Hive_add_3] Hive 进行简单数据处理
0. 说明 通过 Hive 对 duowan 数据进行简单处理 1. 操作流程 1.1 建表 create table duowan(id int, name string, pass string, ...
- hive 中简单的udf函数编写
.注册函数,使用using jar方式在hdfs上引用udf库. $hive.注销函数,只需要删除mysql的hive数据记录即可. delete from func_ru ; delete from ...
- hive中简单介绍分区表(partition table)——动态分区(dynamic partition)、静态分区(static partition)
一.基本概念 hive中分区表分为:范围分区.列表分区.hash分区.混合分区等. 分区列:分区列不是表中的一个实际的字段,而是一个或者多个伪列.翻译一下是:“在表的数据文件中实际上并不保存分区列的信 ...
- Hive之简单查询不启用MapReduce
假设你想查询某个表的某一列.Hive默认是会启用MapReduce Job来完毕这个任务,例如以下: 01 hive> SELECT id, money FROM m limit 10; 02 ...
- hive的简单使用
一.一些说明 1.支持的操作 hive 默认不支持updata 和 delete操作 insert也是执行缓慢,主要用于数据的计算 hive 数据类型---字符串,大部分与java一致. 2.内外表的 ...
- hadoop生态系统学习之路(六)hive的简单使用
一.hive的基本概念与原理 Hive是基于Hadoop之上的数据仓库,能够存储.查询和分析存储在 Hadoop 中的大规模数据. Hive 定义了简单的类 SQL 查询语言,称为 HQL.它同意熟悉 ...
随机推荐
- hdu6071(最短路)
hdu6071 题意 四个点连接形成一个环,给出相邻两个点的距离,求从点 \(2\) 出发再回到 \(2\) 的路程大于等于 \(K\) 的最小值. 分析 首先我们让 \(w=min(d12, d23 ...
- [Atcoder Grand Contest 002] Tutorial
Link: AGC002 传送门 A: …… #include <bits/stdc++.h> using namespace std; int a,b; int main() { sca ...
- 【字符串哈希】bzoj3916 [Baltic2014]friends
枚举断点,哈希判断. #include<cstdio> using namespace std; typedef unsigned long long ull; ull hs,hs1,hs ...
- 【贪心】【线性基】bzoj2844 albus就是要第一个出场
引用题解:http://blog.csdn.net/PoPoQQQ/article/details/39829237 注意评论区. #include<cstdio> using names ...
- 【Trie+DP】BZOJ1212-[HNOI2004]L语言
[题目大意]给出字典和文章,求出文章能够被理解的最长前缀. [思路] 1A……!先用文章建立一棵Trie树,然后对于文章进行DP.f[i]表示文章中长度为i的前缀能否被理解,如果f[i]能理解,顺着下 ...
- Linux查找某个时间点后生成的文件(转)
需要找到某天(例如2017-04-13)以及这之后生成的空文件.那么这个要怎么处理呢?这个当然是用find命令来解决.如下所示, -mtime -5表示查找距现在5*24H内修改过的文件 -type ...
- Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明
Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明 FLOOR——对给定的数字取整数位SQL> select floor(2345.67) from dua ...
- C#将json字符串解析成对象
首先我们在客户端生成json字符串,通过ajax把该字符串传到服务器端 //这是一个以id,email,age的json字符串 var jdata="[{\"id\&quo ...
- 看懂ios命名规则
http://liangrui.blog.51cto.com/1510945/509289/ http://daniellee520.blog.51cto.com/372529/229615
- sping boot 入门
http://www.cnblogs.com/ityouknow/p/5662753.html http://blog.csdn.net/lxhjh/article/details/51711148 ...