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 练习 简单任务处理的更多相关文章

  1. Hive 的简单使用及调优参考文档

    Hive 的简单使用及调优参考文档   HIVE的使用 命令行界面 使用一下命令查看hive的命令行页面, hive --help --service cli 简化命令为hive –h 会输出下面的这 ...

  2. [转]Hive:简单查询不启用Mapreduce job而启用Fetch task

    转自:http://www.iteblog.com/archives/831 如果你想查询某个表的某一列,Hive默认是会启用MapReduce Job来完成这个任务,如下: hive> SEL ...

  3. hive中简单介绍分区表

    所介绍内容基本上是翻译官方文档,比较肤浅,如有错误,请指正! hive中创建分区表没有什么复杂的分区类型(范围分区.列表分区.hash分区.混合分区等).分区列也不是表中的一个实际的字段,而是一个或者 ...

  4. [Hive_add_3] Hive 进行简单数据处理

    0. 说明 通过 Hive 对 duowan 数据进行简单处理 1. 操作流程 1.1 建表 create table duowan(id int, name string, pass string, ...

  5. hive 中简单的udf函数编写

    .注册函数,使用using jar方式在hdfs上引用udf库. $hive.注销函数,只需要删除mysql的hive数据记录即可. delete from func_ru ; delete from ...

  6. hive中简单介绍分区表(partition table)——动态分区(dynamic partition)、静态分区(static partition)

    一.基本概念 hive中分区表分为:范围分区.列表分区.hash分区.混合分区等. 分区列:分区列不是表中的一个实际的字段,而是一个或者多个伪列.翻译一下是:“在表的数据文件中实际上并不保存分区列的信 ...

  7. Hive之简单查询不启用MapReduce

    假设你想查询某个表的某一列.Hive默认是会启用MapReduce Job来完毕这个任务,例如以下: 01 hive> SELECT id, money FROM m limit 10; 02 ...

  8. hive的简单使用

    一.一些说明 1.支持的操作 hive 默认不支持updata 和 delete操作 insert也是执行缓慢,主要用于数据的计算 hive 数据类型---字符串,大部分与java一致. 2.内外表的 ...

  9. hadoop生态系统学习之路(六)hive的简单使用

    一.hive的基本概念与原理 Hive是基于Hadoop之上的数据仓库,能够存储.查询和分析存储在 Hadoop 中的大规模数据. Hive 定义了简单的类 SQL 查询语言,称为 HQL.它同意熟悉 ...

随机推荐

  1. 11、Django实战第11天:templates模板继承

    Django模板的继承,它首先定义一个整体的框架(父类),然后动态的部分(子类)只需要重写自己本身的代码就可以了. 1.在templates目录下创建base.html 2.把org-list.htm ...

  2. [PKUSC2018]最大前缀和(DP)

    题意:求一个序列随机打乱后最大前缀和的期望. 考场上发现不管怎么设状态都写不出来,实际上只要稍微转换一下就好了. 一个前缀[1..k]是最大前缀,当且仅当前面的所有后缀[k-1,k],[k-2,k], ...

  3. [BZOJ 2768] 冠军调查

    Link:https://www.lydsy.com/JudgeOnline/problem.php?id=2768 Solution: 一道比较基础的最大流的题目 一般看到将点分为两类的题目就要往网 ...

  4. 使用IDEA创建package

    1)使用IDEA创建java工程 什么也不选,直接点击Next 无脑继续下一步 点击“Finish”完成工程的创建. 2)在使用IDEA创建了工程之后,首先选中“src”文件夹,然后 紧接着输入包名 ...

  5. C++11简要介绍

    概述  C++1x (本教程中指 C++11/14, 甚至 C++17) 为传统 C++ 注入的大量特性使得整个 C++ 变得更加像一门现代化的语言.C++1x 不仅仅增强了 C++ 语言自身的可用性 ...

  6. touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

    问题:在从 https://c.163.com/hub#/m/repository/?repoId=3093 下载镜像 docker pull hub.c.163.com/library/jenkin ...

  7. FX Composer VS RenderMonkey 【转】

    http://blog.csdn.net/debugconsole/article/details/50905398 FX COMPOSER 其实编辑一个shader到debug它,有很多方法,很多方 ...

  8. IOS Vsync

    vsync count Don't Sync Application.targetFrameRate 设置FPS上限 Every Second VBlank 30 Every VBlank 60 An ...

  9. Hibernate 参数匹配查询

    第一种: public User validate(String userName, String password) { String hql = "from User where use ...

  10. [Python爬虫] 之二十三:Selenium +phantomjs 利用 pyquery抓取智能电视网数据

    一.介绍 本例子用Selenium +phantomjs爬取智能电视网(http://news.znds.com/article/news/)的资讯信息,输入给定关键字抓取资讯信息. 给定关键字:数字 ...