当前位置:网站首页>How to analyze fans' interests?
How to analyze fans' interests?
2022-07-07 03:00:00 【Monkey data analysis】
【 subject 】
There is a “ Fan attention table ”, contain 3 A field : user id、 Follow the media id、 date .
【 problem 】“ Fan attention table ” There is a situation that one user pays attention to multiple media at the same time , such as : user id by A001 Users of , Focus on the media id The data is 1010,1020,1031. In order to facilitate the later analysis of fans' interests , Please split this situation in the table into multiple .
For example, for users A001, Its conversion is as follows :
【 Their thinking 】
Such problems are called “ Column turned ”, stay MySQL There are generally three steps to deal with it :
1) Create a “ Sequence table ”;
2) Join multiple tables , Copy each piece of data in the original table into multiple pieces ;
3) Use substring_index Function to get the final result .
First step : establish Sequence table
“ Sequence table ” It means that there is only one field , Stored is a sequence of numbers , such as :
among ,“ Sequence ” The maximum value of is the maximum number of media a user pays attention to in this problem .
select max(length( Follow the media id) - length(replace( Follow the media id,',','')) + 1) as The maximum number of media attention
from Fan attention table ;
The return result is :
Then we need new “ Sequence table ” Namely :
The second step : Multi table join
Use multi table join , Can pass “ Sequence table ” take “ Fan attention table ” Each line of becomes multiple lines .
Here are two points to note :
1) To ensure that every piece of data in the original table is not lost , choice “ Left link ”, And take the original table as the left table ;
2) The number of copies is limited in the connection condition , The limiting condition is the number of media users pay attention to , namely “ Follow the media id” The number of commas under the field plus 1.
select t1. user id,
t1. Follow the media id,
t1. date ,
t2. Sequence
from Fan attention table t1
left join Sequence table t2 on t2. Sequence <= (length( Follow the media id) - length(replace( Follow the media id,',','')) + 1);
The return result is :
The third step : Use the function to get the result
The next step is to put the media id Intercept it , You need to use the string interception function :SUBSTRING_INDEX.
SUBSTRING_INDEX( character string , Separator , Parameters )
among , Separator refers to dividing media in this question id Of “,”;2 Means to separate by separator , Intercept several media from left to right id; If the parameter is negative , It means to intercept several media from right to left id.
select t1. user id,
substring_index(substring_index(t1. Follow the media id,',',t2. Sequence ),',',-1) as Follow the media id,
t1. date
from Fan attention table t1
left join Sequence table t2 on t2. Sequence <= (length( Follow the media id) - length(replace( Follow the media id,',','')) + 1);
The return result is :
【 The test point of this question 】
1) Check your understanding of the ordered list ;
2) Check the string interception function SUBSTRING_INDEX Understanding ;
3) Check your understanding of multi table connections .
▼ Click on 「 Read the original 」
▼ Unlock more data analysis courses
边栏推荐
- 用全连接+softmax对图片的feature进行分类
- INS/GPS组合导航类型简介
- Redis getting started complete tutorial: common exceptions on the client
- 巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
- Andrews - multimedia programming
- Software testing -- common assertions of JMeter interface testing
- The 8 element positioning methods of selenium that you have to know are simple and practical
- Redis入门完整教程:复制配置
- Cloud Mail .NET Edition
- Use of promise in ES6
猜你喜欢
实施MES管理系统时,哪些管理点是需要注意的
Django数据库(SQlite)基本入门使用教程
Kysl Haikang camera 8247 H9 ISAPI test
Unity uses maskablegraphic to draw a line with an arrow
Dotconnect for DB2 Data Provider
服装企业部署MES管理系统的五个原因
KYSL 海康摄像头 8247 h9 isapi测试
Electrical engineering and automation
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
Software testing -- common assertions of JMeter interface testing
随机推荐
数论 --- 快速幂、快速幂求逆元
简单冒泡排序
The 8 element positioning methods of selenium that you have to know are simple and practical
Read fast RCNN in one article
Contribution of Writing Series
HAVE FUN | “飞船计划”活动最新进展
Work of safety inspection
MES管理系统的应用和好处有哪些
牛客编程题--必刷101之双指针篇
6-6 vulnerability exploitation SSH security defense
Classify the features of pictures with full connection +softmax
服装企业部署MES管理系统的五个原因
CSDN summer camp course project analysis
Have fun | latest progress of "spacecraft program" activities
Static proxy of proxy mode
实施MES管理系统时,哪些管理点是需要注意的
Summary of basic debugging steps of S120 driver
[socket] ① overview of socket technology
What management points should be paid attention to when implementing MES management system
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (filtering part)