#!/bin/sh

#线上线下会员手机号
allMobileSql="
select distinct x_cellphone from
(
select x_cellphone from sourcedata.s_loy_member
union all
select mobile as x_cellphone from sourcedata.def_members 
)temp
";

#会员最近时间的极光id
jgSql="
select user_id,reg_id from(
select a.*,row_number() over(partition by a.user_id order by a.last_time desc) as rn from(
select user_id,reg_id,max(create_time) last_time from sourcedata.device_mapping group by user_id,reg_id)a)t where rn<=1
"

#线上会员信息
onlineSql="
select d.id,d.vipcard_no,d.mobile,d.regtime,s.internal,b.channel,b.device_id,b.phone_brand,b.phone_model,b.gps_adress, t.type,m.reg_id
from sourcedata.def_members d left join sourcedata.distributor t on d.id=t.user_id left join sourcedata.def_member_siebel_mem s on d.id=s.member_id
 left join 
 ($jgSql) m on d.id=m.user_id
left join 
(
 select distinct a.device_id,a.uid,a.channel,a.phone_brand,a.phone_model,a.gps_adress from tracker.base_info a inner join
 (select uid,max(client_time) ct from tracker.base_info where uid is not null group by uid) temp 
 where a.uid=temp.uid and a.client_time=temp.ct 
) b on d.id=cast(b.uid as bigint) 
";

#线下会员信息
offlineSql="
select m.x_cellphone,c.x_vipcardno,m.created,x.attrib_34,x.attrib_26,cx.mrgstatus,m.reg_channel_cd
from sourcedata.s_loy_member m left join sourcedata.s_loy_card c on m.row_id=c.member_id
left join sourcedata.s_loy_member_x x on m.row_id=x.par_row_id
left join sourcedata.cx_member_x cx on m.row_id=cx.par_row_id
";

#生成中间表-基础信息
memberBaseInfoSql="
use tmp;
drop table if exists tmp.member_base_info;
create table tmp.member_base_info as
select o.id as user_id, (case when o.vipcard_no is not null then o.vipcard_no else f.x_vipcardno end) vipcardno,
t.x_cellphone as mobile,
(case length(regexp_extract(t.x_cellphone, '^((1[358][0-9])|(14[57])|(17[0678])|(19[7]))\\d{8}$',0)) when 11 then '是' else '否' end) is_valid,
o.device_id,
o.reg_id,
from_unixtime(o.regtime) as online_regtime,from_unixtime(unix_timestamp(f.created) + 28800) as offline_regtime,
from_unixtime(least(o.regtime,unix_timestamp(f.created) + 28800)) as regtime,
f.attrib_34 as sex,f.attrib_26 as birthday,o.channel,o.phone_brand,o.phone_model,
(case o.type when 2 then 1 else 0 end) as is_distributor,
(case o.internal when 1 then 1 else 0 end) as is_internal,
f.mrgstatus,
0 as has_children,
(case when o.mobile is not null and f.x_cellphone is not null then 1 when f.x_cellphone is not null then 2 end) as member_type,
1 as buyer_type,
datediff(from_unixtime(unix_timestamp()), from_unixtime(least(o.regtime,unix_timestamp(f.created) + 28800))) as regdays,
(case 
 when f.reg_channel_cd  in('门店','潜在会员转入','手工录入' ,'扫门店码入会') then '门店' 
 when f.reg_channel_cd ='来伊份APP' then '来伊份APP'
 when f.reg_channel_cd  in('天猫','天猫旗舰店入会','微信') then '第三方'
 when f.reg_channel_cd  in('宝钢系统', '官网','后台',null) then '其他'
 end
) reg_source,
'' as reg_source_online,
(case when o.gps_adress is not null then o.gps_adress else f.reg_channel_cd end) as province
from
($allMobileSql)t
left join
($onlineSql)o
on t.x_cellphone=o.mobile
left join
($offlineSql)f on t.x_cellphone=f.x_cellphone
";

hive -e "$memberBaseInfoSql"

#还有实名认证/买家信息/省份/注册来源几个中间表信息未作处理,最后处理

用户画像之基本属性信息相关推荐

  1. SparkSQL电商用户画像(五)之用户画像开发(客户基本属性表)

    7.1用户画像–数据开发的步骤 u 数据开发前置依赖 -需求确定 pv uv topn -建模确定表结构 create table t1(pv int,uv int,topn string) -实现方 ...

  2. 关于用户画像产品构建和应用的几点经验

    https://zhuanlan.zhihu.com/p/27329292 贝聊是一款提供给幼儿园使用的APP,兼具"工具属性"."社交属性"和"资源 ...

  3. 用户研究:深度解析用户画像

    "用户画像作为一种设计工具,可以很好得帮助设计师跳出"为自己设计"的惯性思维,聚焦目标用户,发现核心价值,赋能产品,在互联网各类型产品中有广泛的应用. 在产品研发过程中, ...

  4. 用SparkSQL构建用户画像标签

    用SparkSQL构建用户画像 - 伪全栈的java工程师 - 博客园 一.  前言 大数据时代已经到来,企业迫切希望从已经积累的数据中分析出有价值的东西,而用户行为的分析尤为重要. 利用大数据来分析 ...

  5. 用SparkSQL构建用户画像

    用SparkSQL构建用户画像 二.  前言 大数据时代已经到来,企业迫切希望从已经积累的数据中分析出有价值的东西,而用户行为的分析尤为重要. 利用大数据来分析用户的行为与消费习惯,可以预测商品的发展 ...

  6. 用户画像之电商大数据

    一. 前言 大数据时代已经到来,企业迫切希望从已经积累的数据中分析出有价值的东西,而用户行为的分析尤为重要.利用大数据来分析用户的行为与消费习惯,可以预测商品的发展的趋势,提高产品质量,同时提高用户满 ...

  7. python用户画像_京东小家电用户画像分析(python+tableau)

    一.项目背景 京东电商平台最近小家电类目的订单数量.产品浏览量和搜索数量等均有所下降,相关部门计划对小家电类目进行一次促销活动,希望能针对小家电用户的特征提出相应的建议. 二.需求拆解 促销活动主要包 ...

  8. 看完秒懂大数据用户画像!

    来自:网络 什么是用户画像? 用户画像(User Profile),作为大数据的根基,它完美地抽象出一个用户的信息全貌,为进一步精准.快速地分析用户行为习惯.消费习惯等重要信息,提供了足够的数据基础, ...

  9. 金融行业如何用大数据构建精准用户画像?

    原文地址:https://www.jianshu.com/p/6e0a0ca5948e 1. 什么是用户画像? 2. 用户画像的四阶段 用户画像的焦点工作就是为用户打"标签",而一 ...

最新文章

  1. shadow fight 1.6.0 内购
  2. N次剩余(详解+例题+代码)
  3. redis 亿级查询速度_吊打面试官系列:Redis 性能优化的 13 条军规大全
  4. Javascript数据类型共有六种
  5. c语言程序设计2试卷答案,《C语言程序设计》试卷2参考答案.doc
  6. 由一维数组表示的N维数组实现(C++)
  7. [zhuan]asp.net程序性能优化的七个方面 (c#(或vb.net)程序改进)
  8. 橡胶软接头的安装及使用说明
  9. 【数学建模】模型的评价、模型的推广与改进
  10. 基于[三星6818]I2C驱动开发的0.96寸oled屏
  11. 二层交换机实现不同vlan通信
  12. mongodb-报错FailedToParse: Password must be URL Encoded for mongodb:// URL:
  13. 美女直播这么火,那你知道怎么测试直播软件吗?
  14. 三十.什么是vm和vc?
  15. Q/W防洪跳转页面/微信小程序跳转到未备案域名
  16. 一位厦门大学CV硕士毕业生文言文致谢!畅聊三年求学路
  17. 小米路由器mini刷老毛子固件遇到的问题
  18. 常州SEO姜东:tiktok(国际抖音)运营教程:打造高权重账号
  19. 黑莓Z30评测–黑莓10中的均衡之作
  20. linux - grep命令

热门文章

  1. python variables_Python variables.PartitionedVariable方法代码示例
  2. 运行tomcat时,解析 HTTP 请求 header 错误 Note: further occurrences of HTTP 在方法名称中发现无效的字符串, HTTP 方法名必须是有效的符号
  3. 说一下R语言的strptime()及衍生的一些时间序列的格式及使用问题
  4. wps图表中如何插入甘特图_如何通过使用D3可视化数据集来构建类似甘特图的图表...
  5. 想要简单轻松创建柱状图是怎么做到的?
  6. CheatEngine 多级指针 基址、偏移量、拓扑分析图
  7. IDEA第二章----配置git、tomcat(热部署)、database,让你的项目跑起来
  8. 涂鸦模组开发(压力传感器HX711)
  9. python爬虫接单-资料总结
  10. html用户修改信息,用户信息脱敏-规则说明.html