网站首页 > 知识剖析 正文
最近来访标签案例:
1.最近一次来访距今天天数:
最近一次来访距今天数从用户的访问日志表(ods.page_view_log)中抽取,脚本执行如下:
从日志访问表中抽取,这样会产生一张表:user_cookie_relation 用户cookie关系表
基于cookie id 和 最近访问的日期进行排序,每个cookie id 只拿取它最近一次访问的时间。
怎么样操作的?每个cookie id 只收取他最近一次访问的时间。
解释:row_number() over (paritition by cookie_id order by last_visit_time desc)
基于cookie_id 做分区,在分区中,根据最近访问时间做降序排序
解释:row_number() over (paritition by cookie_id order by last_visit_time desc)
基于cookie_id 做分区,在分区中,根据最近访问时间做降序排序
将上一步注册到视图的数据插入cookie 的用户标签表中,执行如下脚本:
ACTION_C_02_001 : 最近天数 (labelid)
userid :用户的cookie id
labelweight: 距今的天数
labelid: ACTION_C_02_1
插入表 dw.userprofile_action_all (行为属性维度表,按照分区插入-- 分区基于 日期,距今天数(labelid = action_c_02_001) 进行分区)
源表:
从 user_cookie_relation :上一步产生的表
选择列信息:
- labelid(Action_c_02_001):标签
- cookieid: cookieid 信息
- labelweight:该cookie距今访问最近的天数
datediff(to_date("data_date"),concat(substr(last_date,1,4),'-',substr(last_date,5,2),'-',substr(last_date,7,2))) as labelweight
1.日期比较函数: datediff
语法: datediff(string enddate,string startdate)
返回值: int
说明: 返回结束日期减去开始日期的天数。
举例:
hive> select datediff(‘2019-07-02’,‘2019-07-01’);
结果:
1
2. to_date:日期时间转日期函数
select to_date('2015-04-02 13:34:12');
输出:2015-04-02
3. concat() 的内容:
语法: CONCAT(string A, string B…)
返回值: string
说明:返回输入字符串连接后的结果,支持任意个输入字符串
举例:
Hive> select concat(‘abc’,'def’,'gh’) from lxw_dual;
abcdefgh
4. 检查日期函数
语法: substr(string A, int start, int len),substring(string A, intstart, int len),用法一样,三个参数
返回值: string
说明:返回字符串A从start位置开始,长度为len的字符串
猜你喜欢
- 2024-11-12 Linux运维面试sql语句2 面试linux运维工程师提问哪些问题
- 2024-11-12 PowerBI时间日期函数 powerbi日期相减
- 2024-11-12 数据库日期与时间函数概览 数据库时间日期型
- 2024-11-12 扎心了!面试时遇到要手写sql,结果函数拼写不出来
- 2024-11-12 还不用Excel算算离国庆还有多少天?Get这11个神技每天省2小时!
- 2024-11-12 种猪生产数据预处理方法之数据清洗
- 2024-11-12 Mysql数据库常见函数(下)——日期时间函数
- 2024-11-12 MySQL常用函数之日期函数 mysql日期yyyymmdd
- 2024-11-12 MySQL常用函数,程序员真得看看 mysql常见函数
- 2024-11-12 日期数据如何比较? 日期比较js
- 04-29php开发者composer使用看这一篇就够了
- 04-29引用和变量声明在不同语言中的实作
- 04-29PHP 没你想的那么差
- 04-29Ubuntu linux 上的 Nginx 和 Php 安装
- 04-29CentOS下通过yum搭建lnmp(单版本PHP)
- 04-29为什么 PHP8 是个高性能版本
- 04-29PHP8函数包含文件-PHP8知识详解
- 04-29使用无参数函数进行命令执行
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)