zoukankan      html  css  js  c++  java
  • 自然周与自然月的Hive统计SQL

    按照周或者月统计活跃数:

    周:

    SELECT week, COUNT(DISTINCT pin), business_type
    FROM (
    	SELECT DISTINCT user_log_acct AS pin,weekofyear(dt) AS week
    		, CASE locate('bdp', url_domain)
    			WHEN 0 THEN 'pinpiao'
    			ELSE 'caixiao'
    		END AS business_type
    	FROM gdm.gdm_online_log
    	WHERE ((url_domain LIKE '%tmall.com%'
    			OR url_domain LIKE '%bdp.tmall.com%')
    		AND user_log_acct NOT IN ('xxx', 'xx111', 'xxx22')
    		AND dt >= '2018-07-30')
    ) weekTab
    GROUP BY week, business_type;
    

      

    月:

    SELECT month, COUNT(DISTINCT pin), business_type
    FROM (
    	SELECT DISTINCT user_log_acct AS pin, month(dt) AS month
    		, CASE locate('bdp', url_domain)
    			WHEN 0 THEN 'brand'
    			ELSE 'caixiao'
    		END AS business_type
    	FROM gdm.gdm_online_log
    	WHERE ((url_domain LIKE '%xx.xx.com%'
    			OR url_domain LIKE '%aa.bdp.aaa.com%')
    		AND user_log_acct NOT IN ('aaa', 'bbb', 'ccc')
    		AND dt >= '2018-08-01')
    ) monthTab
    GROUP BY month, business_type;
    

      

    主要是日期函数的使用!!!!!

    https://www.cnblogs.com/MOBIN/p/5618747.html

    https://www.tutorialspoint.com/hive/hive_built_in_functions.htm

    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

  • 相关阅读:
    jaxb解析xml工具类
    JQuery的父、子、兄弟节点查找方法
    jw player 配置参数
    jQuery判断当前元素是第几个元素&获取第N个元素
    正则表达式中test,match,exec区别
    php常用函数file
    php常用函数time
    php常用array函数
    php常用string函数
    Linux常用命令
  • 原文地址:https://www.cnblogs.com/leodaxin/p/10108439.html
Copyright © 2011-2022 走看看