<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fan on Medium]]></title>
        <description><![CDATA[Stories by Fan on Medium]]></description>
        <link>https://medium.com/@fan00134?source=rss-57781f3e1d5e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*KL1xaG2wNktDdbw6D9_Heg.jpeg</url>
            <title>Stories by Fan on Medium</title>
            <link>https://medium.com/@fan00134?source=rss-57781f3e1d5e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:52:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fan00134/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Alibaba User behavior Analysis]]></title>
            <link>https://medium.com/@fan00134/alibaba-user-behavior-analysis-d6533534d85f?source=rss-57781f3e1d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6533534d85f</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[rfm]]></category>
            <category><![CDATA[marketing-funnels]]></category>
            <category><![CDATA[ecommerce]]></category>
            <dc:creator><![CDATA[Fan]]></dc:creator>
            <pubDate>Tue, 26 May 2020 02:53:08 GMT</pubDate>
            <atom:updated>2020-05-26T02:59:49.649Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NkKL-4TJyFKpfGMt.png" /></figure><h3>Business Content</h3><p>E-commerce has become an indispensable part of our lives. With the improvement of living standards, the transaction volume of Taobao (Alibaba) is increasing year by year. This article has used some Taobao (Alibaba) user data for analysis, with the intention of getting some valuable information in order to provide users with a better online shopping experience.</p><h3>Data Cleaning</h3><h4>Select subset</h4><p>Because the raw data has more than 100M rows, we don’t have enough storage to load all of them. Here we select only the first 1M rows for analysis.</p><pre>DATA_PATH = &#39;/Users/Documents/project/Alibaba user behavior analysis/dataset/UserBehavior.csv&#39;<br>df = pd.read_csv(DATA_PATH, nrows = 1000000)<br>target_name = &#39;/UsersDocuments/project/Alibaba user behavior analysis/dataset/UserBehavior_small.csv&#39;<br>df.to_csv(target_name)</pre><h4>Load data into SQL Database</h4><p>I renamed the columns in this data file as user_id, item_id, cate_id, behavior_type, and timestamp. And when the transformed CSV data was loaded into the SQL database, we need to make sure every column except the timestamp is the VARCHAR type while the timestamp column is INT type.</p><h4>Duplicates Detection</h4><ol><li>We treat the rows with the same users_id, item_id, and timestamp as duplicates.</li></ol><pre>SELECT user_id,<br>       item_id,<br>       TIMESTAMP<br>FROM userbehavior_small<br>GROUP BY user_id,<br>         item_id,<br>         TIMESTAMP<br>HAVING count(1) &gt; 1</pre><p>The result shows there is no duplicate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*T2ibhZO2fMtnWZ7xJQSXRg.png" /></figure><p>2. Create a new table called u_b to store distinct raw data.</p><pre>CREATE TABLE u_b<br>SELECT *<br>FROM userbehavior_small<br>GROUP BY user_id,<br>         item_id,<br>         cate_id,<br>         behavior_type,<br>         TIMESTAMP</pre><h4>Missing Value Treatment</h4><pre>SELECT COUNT(user_id), COUNT(item_id), COUNT(cate_id), COUNT(behavior_type), COUNT(timestamp)<br>FROM u_b</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*MsEMsZRmUj-dB7R_ihOtVw.png" /></figure><p>The result shows there is no missing value.</p><h4>Unifying Process</h4><ol><li>Add ID column as PK.</li></ol><pre>ALTER TABLE u_b ADD ID int unsigned primary key auto_increment</pre><p>2. Add columns ‘longdate’, ‘date’ and ‘time’ to store the time.</p><pre>ALTER TABLE u_b ADD(longdate VARCHAR(255), date VARCHAR(255), time VARCHAR(255));</pre><p>3. Transform the timestamp, and store it in ‘longdate’, ‘date’ and ‘time’.</p><pre>UPDATE u_b SET longdate=FROM_UNIXTIME(timestamp,&#39;%Y-%m-%d %k:%i:%s&#39;), date=FROM_UNIXTIME(timestamp,&#39;%Y-%m-%d&#39;), time=FROM_UNIXTIME(timestamp,&#39;%k:%i:%s&#39;) WHERE ID BETWEEN 1 and 1000000;</pre><p>4. Add hour column.</p><pre>ALTER TABLE u_b ADD hour INTEGER(30);<br>UPDATE u_b SET hour = HOUR(time);</pre><h4>Anomalies Treatment</h4><p>Based on the intro of this dataset, the data should be between 2017/11/25 to 2017/12/3. Therefore we treat any data outside this range as anomalies.</p><pre>SELECT COUNT(longdate)<br>FROM u_b<br>WHERE longdate&lt;&#39;2017-11-25 00:00:00&#39; OR longdate &gt;&#39;2017-12-03 24:00:00&#39;;</pre><p>And then we deleted those anomalies.</p><pre>DELETE FROM u_b<br>WHERE longdate&lt;&#39;2017-11-25 00:00:00&#39; or longdate &gt;&#39;2017-12-03 24:00:00&#39;;</pre><p>A basic data summary:</p><pre>SELECT <br>COUNT(DISTINCT user_id) AS user_amount,<br>COUNT(DISTINCT item_id) AS item_amount,<br>COUNT(DISTINCT cate_id) AS item_cate_amount,<br>SUM(CASE WHEN behavior_type = &#39;pv&#39; THEN 1 ELSE 0 END) AS pv_amount,<br>SUM(CASE WHEN behavior_type = &#39;fav&#39; THEN 1 ELSE 0 END) AS favor_amount,<br>SUM(CASE WHEN behavior_type = &#39;cart&#39; THEN 1 ELSE 0 END) AS add_cart_amount,<br>SUM(CASE WHEN behavior_type = &#39;buy&#39; THEN 1 ELSE 0 END) AS purchase_amount,<br>COUNT(longdate) AS total_amount<br>FROM u_b;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*C75VqW5MDQFbklK31DiBzg.png" /></figure><h3>Set Up Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iq7KItVJCZHtCJOc2jlw1w.png" /></figure><p>Note:</p><ol><li>Since we don’t have data for AOP and Profit Ratio, we will not conduct analysis on this part.</li><li>Since we don’t know about M in this RFM model, we will not focus on this part.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-eu5xrMz_6_dOBanwREKw.png" /></figure><h3>Analysis Logic</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-0Jg2eteP_z1ldvmOe1bg.png" /></figure><h3>Exploratory Data Analysis</h3><h4>1. From users</h4><h4>(a) Page View &amp; Unique Visit Analysis</h4><pre>-- Find the amount of Page Visit GROUP BY DATE<br>CREATE TABLE page_visit_date AS (<br>SELECT DATE, count(behavior_type) AS total_pv <br>FROM u_b<br>WHERE behavior_type=&#39;pv&#39;<br>GROUP BY DATE<br>ORDER BY DATE ASC<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xKn5Z1zifA-hILbRbtPusw.png" /></figure><p>Bounce Rate: No action on the websites.</p><pre>-- Calculate the Bounce Rate<br>SELECT <br>(SELECT count(DISTINCT user_id) FROM u_b<br>WHERE user_id NOT IN <br>(SELECT DISTINCT user_id FROM u_b WHERE behavior_type=&#39;fav&#39;)<br>AND user_id NOT IN<br>(SELECT DISTINCT user_id FROM u_b WHERE behavior_type=&#39;cart&#39;)<br>AND user_id NOT IN <br>(SELECT DISTINCT user_id FROM u_b WHERE behavior_type=&#39;buy&#39;) ) / (SELECT count(DISTINCT user_id) FROM u_b);</pre><p>The Bounce Rate is high, around 80%. We might want to pay attention to the detailed page layout design to make sure it can earn decent conversions.</p><h4>(b) Active User Analysis</h4><pre>-- Find the amount of Active Users group by date<br>CREATE TABLE active_users AS (<br>SELECT DATE, count(DISTINCT(user_id)) AS active_users_date<br>FROM u_b<br>GROUP BY DATE<br>ORDER BY DATE ASC<br>)</pre><p>We can tell from this graph that the active user numbers show a steady trend from Nov 25th to Dec 1st. However, start on Dec 1st, the number shows an increasing trend. We suggest the analyst to do some retrospective analysis on why this happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlYiSYtk7k9p87ZGQD6qYQ.png" /></figure><pre>-- Find the amount of Active Users group by hour<br>SELECT hour, COUNT(DISTINCT(user_id)) AS active_users_hr<br>FROM u_b<br>GROUP BY hour<br>ORDER BY hour ASC</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PmPVXq-27klZvLFi0FXvSw.png" /></figure><p>What we can learn from this graph is that 4 am has the lowest amount of active users. The active users&#39; amount show a stable trend from 10 am to 6 pm, and peaks at around 9 pm.</p><h4>(c) User Behavior Analysis</h4><pre>-- Check the different type of behavior amount across different date<br>CREATE TABLE behavior_type_date AS (<br>SELECT DATE, <br>    SUM(CASE WHEN behavior_type = &#39;pv&#39; THEN 1 ELSE 0 END) AS visit_amount,<br>    SUM(CASE WHEN behavior_type = &#39;cart&#39; THEN 1 ELSE 0 END) AS cart_amount,<br>    SUM(CASE WHEN behavior_type = &#39;fav&#39; THEN 1 ELSE 0 END) AS favorite_amount,<br>    SUM(CASE WHEN behavior_type = &#39;buy&#39; THEN 1 ELSE 0 END) AS purchase_amount<br>FROM u_b<br>GROUP BY DATE<br>ORDER BY DATE ASC<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FizwhvvtyYC6gnTow3XtQg.png" /></figure><p>We can see that the amount of the visit is much larger than the other user behaviors, therefore we will focus on other user behaviors in the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mbwYf91aBehfDbV8PGs_A.png" /></figure><p>All of the four different types of user behaviors are very similar to each other. To quantify this finding, I calculated the correlation matrix.</p><pre>-- Create correlation matrix<br>WITH correlation_CTE AS<br>(<br>SELECT visit_amount AS ROW, <br>       visit_amount AS col, <br>       corr(visit_amount, visit_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT visit_amount AS ROW, <br>       cart_amount AS col, <br>       corr(visit_amount, cart_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT visit_amount AS ROW, <br>       favorite_amount AS col, <br>       corr(visit_amount, favorite_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT visit_amount AS ROW, <br>       purchase_amount AS col, <br>       corr(visit_amount, purchase_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT cart_amount AS ROW, <br>       cart_amount AS col, <br>       corr(cart_amount, cart_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT cart_amount AS ROW, <br>       favorite_amount AS col, <br>       corr(cart_amount, favorite_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT cart_amount AS ROW, <br>       purchase_amount AS col, <br>       corr(cart_amount, purchase_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT favorite_amount AS ROW, <br>       favorite_amount AS col, <br>       corr(favorite_amount, favorite_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT favorite_amount AS ROW, <br>       purchase_amount AS col, <br>       corr(favorite_amount, purchase_amount) AS coeff<br>FROM behavior_type_date<br>UNION<br>SELECT purchase_amount AS ROW, <br>       purchase_amount AS col, <br>       corr(purchase_amount, purchase_amount) AS coeff<br>FROM behavior_type_date<br>)<br>SELECT ROW,<br>       sum(CASE<br>               WHEN col= &#39;visit_amount&#39; THEN coeff<br>               ELSE 0<br>           END) AS visit_amount,<br>       sum(CASE<br>               WHEN col=&#39;cart_amount&#39; THEN coeff<br>               ELSE 0<br>           END) AS cart_amount,<br>       sum(CASE<br>               WHEN col=&#39;favorite_amount&#39; THEN coeff<br>               ELSE 0<br>           END) AS favorite_amount,<br>       sum(CASE<br>               WHEN col=&#39;purchase_amount&#39; THEN coeff<br>               ELSE 0<br>           END) AS purchase_amount<br>FROM corelation_CTE<br>GROUP BY ROW<br>ORDER BY ROW DESC<br>;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*ueNUEUOIFVSe5QodQq1PkA.png" /></figure><p>Again, we confirmed our findings for this step.</p><p>Findings on user behaviors analysis on date granularity:</p><ol><li>The shape of the total amount from each type of user behavior is similar to the date-level active user situation.</li><li>Different types of user behaviors are indeed very similar to each other according to the correlation values.</li><li>Visits are much higher than the other three behaviors. And the 2nd highest — add to cart is also much higher than the rest two behaviors.</li></ol><p>To continue on user behavior analysis, I aggregated the data into hour level.</p><pre>-- CHECK the different types of behavior across different hours<br>CREATE TABLE behavior_type_hr AS (<br>SELECT HOUR, <br>    SUM(CASE WHEN behavior_type = &#39;pv&#39; THEN 1 ELSE 0 END) AS visit_amount,<br>    SUM(CASE WHEN behavior_type = &#39;cart&#39; THEN 1 ELSE 0 END) AS cart_amount,<br>    SUM(CASE WHEN behavior_type = &#39;fav&#39; THEN 1 ELSE 0 END) AS favorite_amount,<br>    SUM(CASE WHEN behavior_type = &#39;buy&#39; THEN 1 ELSE 0 END) AS purchase_amount<br>FROM u_b<br>GROUP BY HOUR<br>ORDER BY HOUR ASC<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCLEaiiOTlKgE-weOTdU9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSIBO-L-uShcq8cNfg4ejQ.png" /></figure><p>Findings on user behaviors analysis from hour granularity:</p><ol><li>The shape of the total amount from each type of user behavior is similar to the hour-level active user situation.</li><li>Same findings 2.3 from date level analysis.</li></ol><h4>(d) RFM model Analysis</h4><p>As we mentioned in the Analysis Logic section, we will not analyze <strong>M(Monetary)</strong>.</p><p><strong>R(Recency):</strong></p><p>Since the time range from 11/25 to 12/03, here we will set 11/25 as a base reference. That’s being said, we will set diffrent level by measuring the distance from 11/25. 0–2 days corresponds to 1, 3–4 days corresponds to 2, 5–6 days corresponds to 3 and 7–8 days corresponds to 4.</p><pre>-- Recency:<br>CREATE TABLE score_01 AS<br>SELECT user_id,<br>(CASE WHEN purchase_time_period BETWEEN 0 AND 2 THEN 1<br>WHEN purchase_time_period BETWEEN 3 AND 4 THEN 2<br>WHEN purchase_time_period BETWEEN 5 AND 6 THEN 3<br>WHEN purchase_time_period BETWEEN 7 AND 8 THEN 4 ELSE 0 END<br>) AS recency_rate<br>FROM<br>(SELECT user_id,datediff(max(DATE),&#39;2017-11-25&#39;) AS purchase_time_period<br>FROM u_b<br>WHERE behavior_type=&#39;buy&#39;<br>GROUP BY user_id) AS a<br>ORDER BY recency_rate;</pre><pre>SELECT * FROM score_01;</pre><p><strong>F(Frequency)：</strong></p><p>First we need to find the highest frequency stats.</p><pre>SELECT user_id,count(user_id) AS purchase_amount FROM u_b<br>WHERE behavior_type=&#39;buy&#39;<br>GROUP BY user_id<br>ORDER BY count(user_id) DESC<br>LIMIT 10;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*vi6OTxGXD0_BN2b4M-i8qA.png" /></figure><p>The result shows that user “3122135” has the highest Frequency of 17. Therefore, we will divide all the users into four different levels, 1–4 corresponds to 1, 5–8 corresponds to 2, 9–12 corresponds to 3, and 13–17 corresponds to 4.</p><pre>CREATE TABLE score_02 AS<br>SELECT user_id,<br>(CASE WHEN purchase_times BETWEEN 1 AND 4 THEN 1<br>WHEN purchase_times BETWEEN 5 AND 8 THEN 2<br>WHEN purchase_times BETWEEN 9 AND 12 THEN 3<br>WHEN purchase_times BETWEEN 13 AND 17 THEN 4 ELSE 0 END <br>)AS frequency_rate<br>FROM<br>(SELECT user_id,count(behavior_type)AS purchase_times<br>FROM u_b<br>WHERE behavior_type=&#39;buy&#39;<br>GROUP BY user_id) b<br>ORDER BY frequency_rate DESC;</pre><pre>SELECT * FROM score_02;</pre><p>To decide who are our most valuable customers, here we calculate the average rate for R and F.</p><pre>-- Calculate the mean rate for Recency and Frequency<br>SELECT AVG(recency_rate) FROM score_01; -- 2.38<br>SELECT AVG(frequency_rate)FROM score_02; -- 1.00</pre><pre>-- Classify users<br>CREATE table users_classify AS<br>SELECT user_id,<br>(CASE WHEN R&gt;2.38 AND F&gt;1 THEN &#39;Most Valuable User&#39;<br>WHEN R&gt;2.38 AND F&lt;=1 THEN &#39;Important Sustainable User&#39;<br>WHEN R&lt;=2.38 AND F&gt;1 THEN &#39;Important Developable User&#39;<br>WHEN R&lt;=2.38 AND F&lt;=1 THEN &#39;Normal User&#39; ELSE 0 END <br>)AS user_type<br>FROM<br>(SELECT a.user_id,a.recency_rate AS R,b.frequency_rate AS F<br>FROM score_01 AS a INNER JOIN score_02 AS b<br>ON a.user_id=b.user_id)c;</pre><pre>SELECT * FROM users_classify;</pre><pre>CREATE TABLE users_classify_result AS (<br>SELECT user_type,count(DISTINCT user_id) AS amount FROM users_classify GROUP BY user_type);</pre><pre>SELECT * FROM users_classify_result ORDER BY amount;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*H5M_m2AB3qPF15fzrUCDLQ.png" /></figure><p>The result shows that only 0.26% of customers are the most Important Users about half of the customers are Normal Users and the other half are Important Sustainable Users. To retain our customers, we need to lay much emphasis on Important Sustainable Users. These types of customers are easy to maintain but at the same time, are likely to be turned into most valuable users.</p><h4>2. From products</h4><h4>(a) Conversion Rate Analysis (Using the funnel model)</h4><pre>-- Create a table to store data for each cuomer<br>CREATE TABLE user_beha AS (<br>SELECT user_id, cate_id,<br>	sum( CASE WHEN behavior_type = &#39;pv&#39; THEN 1 ELSE 0 END ) AS visit,<br>	sum( CASE WHEN behavior_type = &#39;fav&#39; THEN 1 ELSE 0 END ) AS favorite,<br>	sum( CASE WHEN behavior_type = &#39;cart&#39; THEN 1 ELSE 0 END ) AS cart,<br>	sum( CASE WHEN behavior_type = &#39;buy&#39; THEN 1 ELSE 0 END ) AS purchase<br>FROM u_b <br>GROUP BY user_id, cate_id<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*A224cPtaR0QeCREf23lTSQ.png" /></figure><p>Then I will follow these four different types of conversions to analysis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKlZOnfizEHvntlbgnzfZg.png" /></figure><pre>-- Conversion Rate<br>-- Overall Conversion Rate 1.43%<br>SELECT SUM(visit), SUM(purchase), SUM(purchase) / SUM(visit)<br>FROM user_beha <br>WHERE visit &gt; 0;</pre><pre>-- Direct purchase without adding to cart, add to favorite<br>-- Direct Puchase Conversion Rate 1.15%<br>SELECT SUM(visit), SUM(purchase), SUM(purchase) / SUM(visit)<br>FROM user_beha <br>WHERE visit &gt; 0<br>AND favorite = 0<br>AND cart = 0;</pre><pre>-- Indirect Purchase with adding to cart, without adding to favorite<br>-- From Visit to &quot;Add to cart&quot; Conversion Rate 25.75%, from &quot;Add to cart&quot; to purchase Conversion Rate 10.08%, from visit to purchase Conversion Rate 2.6%<br>SELECT SUM(visit), SUM(cart), SUM(purchase), SUM(cart) / SUM(visit), SUM(purchase) / SUM(cart), SUM(purchase) / SUM(visit)<br>FROM user_beha <br>WHERE visit &gt; 0<br>AND favorite = 0<br>AND cart &gt; 0;</pre><pre>-- Indirect Purchase with adding to favorite, without adding to cart<br>-- From Visit to &quot;Add to cart&quot; Conversion Rate 25.21%, from &quot;Add to favorite&quot; to purchase Conversion Rate 6.75%, from visit to purchase Conversion Rate 1.7%<br>SELECT SUM(visit), SUM(cart), SUM(purchase), SUM(favorite) / SUM(visit), SUM(purchase) / SUM(favorite), SUM(purchase) / SUM(visit)<br>FROM user_beha <br>WHERE visit &gt; 0<br>AND favorite &gt; 0<br>AND cart = 0;</pre><pre>-- Indirect Purchase with adding to favorite and adding to cart<br>-- From Visit to &quot;Add to cart&quot; or &quot;Add to favorite&quot; Conversion Rate 20.06%, from &quot;Add to cart&quot; or &quot;Add to favorite&quot; to purchase Conversion Rate 10.42%, from visit to purchase Conversion Rate 2.09%<br>SELECT SUM(visit), SUM(cart), SUM(purchase), (SUM(cart) + SUM(favorite)) / SUM(visit), SUM(purchase) / (SUM(cart) + SUM(favorite)), SUM(purchase) / SUM(visit)<br>FROM user_beha <br>WHERE visit &gt; 0<br>AND favorite &gt; 0<br>AND cart &gt; 0;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*C0oX3ACrbIgF1Sh3bS_Jyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*AJ5nZtHt-vzHBLUBdDjS7Q.png" /></figure><p>Based on the funnel result, we can tell that users are almost equally likely to use “add to cart” and “add to favorite” function. The purchase conversion rate, however, is different for Path 1 and Path2. Users’ conversion rate after “adding to cart” is 1% higher than that after “adding to favorite”.</p><p>One possible reason for that is from the cart page you can directly make a purchase, but for the “favorite list” page, you need to go to the cart page again to make the purchase. The process of purchasing for path 2 will add an additional step compared to path 1. During this process, the website might lose some of its active users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6533534d85f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Enlightening SQL Interview Question]]></title>
            <link>https://medium.com/@fan00134/an-enlightening-sql-interview-question-ff81f2e663fb?source=rss-57781f3e1d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff81f2e663fb</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Fan]]></dc:creator>
            <pubDate>Sun, 26 Apr 2020 05:07:41 GMT</pubDate>
            <atom:updated>2020-05-26T03:01:32.165Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C9K593cmeOjx_AMM.png" /></figure><blockquote>After I almost finished the SQL problems in Leetcode for preparing the Data Analyst interviews, I found out that most of the SQL problems in Leetcode are a little bit deviating from those that are frequently asked in interviews with a business scenario setting. So that is why I started to search for SQL problems from real Tech company’s interview to practice my SQL skills. And this article includes one of the real interview SQL problems from a famous Tech company’s interviewer.</blockquote><h4>Background:</h4><p>We have a user attendance table <strong><em>t_user_attendence</em></strong> which stores the information about whether a user has signed in each day (Note: this table includes the attendance history of every user ever day. It contains three columns，date (<strong><em>date</em></strong>), user_id (<strong><em>fuser_id</em></strong>), and whether the user signed I today (<strong><em>fis_sign_in</em></strong>).</p><h4>Question 1:</h4><p>Calculate the consecutively accumulated signed-in days for each user (the output table only contains user who signs in today and his consecutively accumulated signed-in days)</p><p>The output table<strong><em> t_user_consecutive_days</em></strong>: user_id (<strong><em>fuser_id</em></strong>), user’s consecutive signed-in days (<strong><em>fconsecutive_days</em></strong>).</p><h4>Question 2:</h4><p>Calculate the historical maximum number of consecutive signed-in days of each user (the output table contains all users who have appeared in the user attendance table and the historical maximum number of consecutive signed-in days)</p><p>Output table <strong><em>t_user_max_days</em></strong>: user_id (<strong><em>fuser_id</em></strong>), maximum number of consecutive signed-in days (<strong><em>fmax_days</em></strong>)</p><p><strong><em>Question 1 solution A:</em></strong></p><pre>SET @today = &#39;20200425&#39;<br>select <br>    fuser_id,<br>    datediff(@today,fdate_max) fconsecutive_days<br>from<br>(<br>    select <br>        fuser_id, <br>        max(fdate) fdate_max<br>    from t_user_attendence<br>    where fis_sign_in = 0 <br>        and fuser_id in (select fuser_id from t_user_attendence where fdate = @today and fis_sign_in = 1)<br>    group by fuser_id<br>) t1</pre><p><strong><em>Question 1 solution B:</em></strong></p><pre>select <br>    t2.fuser_id,<br>    count(1) fconsecutive_days<br>from<br>(<br>    select *,<br>        row_number() over (partition by fuser_id order by fdate desc) as rk<br>    from t_user_attendence t1<br>    where fis_sign_in = 1 <br>    and fuser_id in (select fuser_id from t_user_attendence where fdate = @today and fis_sign_in = 1)<br>) t2<br>group by t2.fuser_id, date_add(t2.fdate,t2.rk)<br>having date_add(t2.fdate,t2.rk) = date_add(@today,1)</pre><p><strong><em>Question 2 solution A:</em></strong></p><pre>select<br>    t2.fuser_id,<br>    max(t2.cnt) as max_live_days<br>from<br>(<br>    select<br>        t1.fuser_id,<br>        date_sub(t1.fdate, t1.rk) dt2,<br>        count(1) cnt<br>    from<br>    (<br>        select <br>            fuser_id,<br>            fdate,<br>            row_number() over (partition by fuser_id order by fdate) rk<br>        from table<br>        where fis_sign_in = 1<br>    ) t1<br>    group by t1.fuser_id, date_sub(t1.fdate,t1.rk)<br>)t2<br>group by t2.fuser_id</pre><p><strong><em>Question 2 solution B:</em></strong></p><pre>select fuser_id<br>,max(length(cut_fsign_record)) as fmax_days<br>(select fuser_id<br>,fsign_record<br>,cut_fsign_record<br>from<br>    (select fuser_id<br>    ,wm_concat(fis_sign_in) fsign_record<br>    from t_user_attendence<br>    group by fuser_id<br>    ) t1 <br>lateral view explode(split(fsign_record,&#39;0&#39;)) t as cut_fsign_record<br>) t2<br>where cut_fsign_record&lt;&gt;&#39;&#39;<br>group by fuser_id<br>;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff81f2e663fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>