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. 模板—字符串—Manacher

    模板—字符串—Manacher Code: #include <cstdio> #include <cstring> #include <algorithm> us ...

  2. 14、Flask实战第14天:Flask使用SQLAlchemy

    flask-sqlalchemy使用详解 之前我们用到的SQLAchemy是可以单独使用的,不需要用到Flask 如果我们在Flask框架中使用SQLAchemy,可以使用flask_sqlalche ...

  3. ASP.NET Core 2.2 基础知识(七) 选项模式

    承接上一篇 配置, 选项模式是专门用类来表示相关配置的服务. 基本选项配置 新建一个选项类,该类必须是包含无参数的构造函数的非抽象类. public class MyOptions { public ...

  4. [CF235E]Number Challenge

    $\newcommand{fl}[1]{\left\lfloor#1\right\rfloor}$题意:求$\sum\limits_{i=1}^a\sum\limits_{j=1}^b\sum\lim ...

  5. Android UI 统一修改Button控件的样式,以及其它系统控件的默认样式

    先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下: public Button(Context context, Attribut ...

  6. 使用FluentValidation来进行数据有效性验证

    之前我介绍过了使用系统自带的Data Annotations来进行数据有效性验证,今天在CodePlex上逛的时候,发现了一个非常简洁好用的库:FluentValidation 由于非常简洁,就直接拿 ...

  7. JS中的Math.pow(a,b)方法

    定义和用法 pow() 方法可返回 x 的 y 次幂的值. 语法 Math.pow(x,y) 参数 描述 x 必需.底数.必须是数字. y 必需.幂数.必须是数字. 返回值 x 的 y 次幂. 说明 ...

  8. 用Thunderbird以HTML发邮件,收件人却总是收到文本邮件

    要在通讯录里面,把你要发送的人设置可以接收HTML格式的邮件,那么你才能发出HTML格式. 否则,Thunderbird默认你所发的收件人无法接收HTML格式邮件.

  9. 通过python脚本查看端口

    [root@zabbix-server alertscripts]# cat check_port1.py #!/usr/bin/env python #coding:utf-8 import os, ...

  10. (转)MFC的GUI窗口使用Console输出函数printf

    原文链接 在GUI程序中使用printf函数: #include <io.h> #include <fcntl.h> void InitConsole() { ; FILE* ...