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.它同意熟悉 ...
随机推荐
- SPOJ IITWPC4F - Gopu and the Grid Problem (双线段树区间修改 区间查询)
Gopu and the Grid Problem Gopu is interested in the integer co-ordinates of the X-Y plane (0<=x,y ...
- 【推广】实用命令——tldr
碎碎念 如题,通常遇到一个新的命令需要查询其帮助的时候,一般使用`command -h`或者`man command`来查询,但是,有时候仅仅想知道这个命令怎么用,并不想知道具体含义啊(这个命令可能不 ...
- python url拼接
import datetime,requests import json,time,urllib import hashlib self.url_domain = “www.baidu,com/” u ...
- [BZOJ 3571] 画框
Link: BZOJ 3571 传送门 Solution: 和 BZOJ2395 的建模完全相同,(BZOJ2395 题解传送门) 仅仅是将其中的基础问题由最小生成树改成了二分图最大完美匹配 只要将原 ...
- 【第二类Stirling数】Gym - 101147G - The Galactic Olympics
如果K>n,就无解: 如果K==n,就答案是P(n,n): 如果K<n,答案就是s(n,K)*P(K,K): P为排列数,s为第二类斯特林数. 第二类斯特林数就是将n个球,划分为K个非空集 ...
- 【dfs序】【set】bzoj3991 [Sdoi2015]寻宝游戏
在考试代码的基础上稍微改改就a了……当时为什么不稍微多想想…… 插入/删除一个新节点时就把其dfn插入set/从set中删除. 当前的答案就是dfn上相邻的两两节点的距离和,再加上首尾节点的距离. 比 ...
- 【莫队算法】【权值分块】bzoj3585 mex
orz PoPoQQQ. 本来蒟蒻以为这种离散化以后就对应不起来的题不能权值分块搞的说. ……结果,实际上>n的权值不会对答案作出贡献. #include<cstdio> #incl ...
- 1.2(学习笔记)Servlet基础(doGet、doPost、生命周期、页面跳转)
一.doGet()与doPost() 我们在TestServlet类中重写doGet().doPost().service(). import javax.servlet.ServletExcepti ...
- Java 输入框复用代码
1 int messageType=JOptionPane.INFORMATION_MESSAGE; String message=mines + " minutes is approxim ...
- 实用类String.length应用-用户名密码长度
package demo3; import java.util.Scanner; //会员注册,用户名长度不小于3,密码长度不小于6,两次输入的密码必须相同 public class Register ...