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. HDU 2523 sort (hash)

    #include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...

  2. [JSOI2008]Star War

    星球之间互相直接或间接地连接帝国开始使用死星有计划地摧毁反抗军占领的星球给出星球间隧道的连通情况,已经帝国打击的顺序要求以尽量快的速度求出每一次打击之后反抗军占据的星球的联通快的个数(若两个星球,直接 ...

  3. Codeforces Round 251 (Div. 2)

    layout: post title: Codeforces Round 251 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  4. hdu4757(可持久化 Trie )

    hdu4757 题意 给出一棵树,每个节点有权值,每次查询节点 \((u, v)\) 以及 \(x\) ,问 \(u\) 到 \(v\) 路径上的某个节点与 \(x\) 异或最大的值是多少. 分析 T ...

  5. 13、Django实战第13天:分页列表功能

    我们看课程 机构列表页是需要分页的 为了完成分页功能,我们需要用到Django的一个开源开发库django-pure-pagination workon mxonline pip install dj ...

  6. 2、Django实战第2天:app设计

    app设计:五大模块 users 用户管理 courses 课程管理 organization 机构和教师管理 operation 用户操作管理 新建上面4个模块的app manage.py@mxon ...

  7. Java高级架构师(一)第30节:把应用部署到Linux服务器上

  8. ubuntu使用ssh远程登录服务器及上传本地文件到服务器

    1. ubuntu 远程登录   首先你的ubuntu要能够支持ssh,如果不能,自行百度! 打开终端,输入 ssh  root@115.159.200.13(你的服务器的IP地址) 回车就会让你输入 ...

  9. AppCompatActivity与toolbar的结合

    原文:http://www.51itong.net/android-activity-appcompatactivity-toolbar-15750.html 另外一个博客:Android 5.x T ...

  10. 深入了解JavaScript权威指南

    JavaScript对象可以看作是属性的无序集合,每个属性就是一个键值对,可增可删.JavaScript中的所有事物都是对象:字符串.数字.数组.日期,等等.JavaScript对象除了可以保持自有的 ...