<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tips on Ha Pham</title><link>http://hoanghapham.github.io/tags/tips/</link><description>Recent content in Tips on Ha Pham</description><generator>Hugo -- 0.167.0</generator><language>en-us</language><lastBuildDate>Mon, 07 Feb 2022 20:42:18 +0700</lastBuildDate><atom:link href="http://hoanghapham.github.io/tags/tips/index.xml" rel="self" type="application/rss+xml"/><item><title>Generate Run-Length ID With SQL</title><link>http://hoanghapham.github.io/posts/generate-run-length-id-with-sql/</link><pubDate>Mon, 07 Feb 2022 20:42:18 +0700</pubDate><guid>http://hoanghapham.github.io/posts/generate-run-length-id-with-sql/</guid><description>&lt;h1 id="what-is-run-length-id"&gt;What is run-length ID?&lt;/h1&gt;
&lt;p&gt;Sometimes during analysis work, you need to group &lt;strong&gt;consecutive sequence of values&lt;/strong&gt; into different &amp;ldquo;runs&amp;rdquo;, and calculate metrics for each run. For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Given a time series recording some entity&amp;rsquo;s state, you want to calculate on average, how long does an entity stay in a particular state.
&lt;img loading="lazy" src="http://hoanghapham.github.io/generate-run-length-id-with-sql/consecutive_runs.png"&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Or a more specific example: Given a series of event data of several users, you want to group the users&amp;rsquo; events into sessions with a session cut-off threshold of your choice
&lt;img loading="lazy" src="http://hoanghapham.github.io/generate-run-length-id-with-sql/user_events.png"&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>