TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Everything is a funnel, but SQL doesn't get it

34 pointsby mikpankoalmost 3 years ago

6 comments

mr_gibbinsalmost 3 years ago
Not to play Code Golf here but the premise that retention takes 50+ lines of SQL is plain wrong.<p>Here&#x27;s an implementation (T-SQL) in less than 10 lines. Table setup script is here: <a href="https:&#x2F;&#x2F;pastebin.com&#x2F;9DajyzLp" rel="nofollow">https:&#x2F;&#x2F;pastebin.com&#x2F;9DajyzLp</a> . There are probably even shorter ways of doing it. Anyone who objects to hardcoded dates, just swap out with a relative DATEADD.<p>;WITH lastweek AS ( SELECT USERID, TS, [ACTION] FROM Users WHERE TS BETWEEN &#x27;2022-06-13&#x27; AND &#x27;2022-06-19&#x27; )<p>SELECT ROUND(CAST(f1.[c] AS FLOAT) &#x2F; CAST(f2.[c] AS FLOAT),2) FROM<p>( SELECT COUNT(*) [c] FROM lastweek w INNER JOIN Users u ON w.USERID = u.USERID AND w.[ACTION] = &#x27;A&#x27; AND u.TS BETWEEN &#x27;2022-06-20&#x27; AND &#x27;2022-06-26&#x27; ) f1,<p>( SELECT COUNT(*) [c] FROM Users u WHERE u.[ACTION] = &#x27;A&#x27; ) f2
评论 #31855286 未加载
评论 #31855761 未加载
评论 #31855739 未加载
评论 #31856489 未加载
ZseeBrzalmost 3 years ago
Process Mining is a relatively new field of data analytics, focusing on exactly these types of questions using workflow or activity sequence data. Celonis, one of the biggest players in the field have even developed a query languages called PQL for querying these kind of information from “event logs”
yellowapplealmost 3 years ago
The second example (with the sequences v. the table of boolean columns) seems like it&#x27;d be immediately resolved by replacing those booleans with timestamps.
评论 #31856462 未加载
PaulHoulealmost 3 years ago
See<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Complex_event_processing" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Complex_event_processing</a><p>and<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Datalog" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Datalog</a>
ekzhualmost 3 years ago
Check out MATCH_RECOGNIZE. It is a new SQL feature that does just what the post describes.
garyclarke27almost 3 years ago
The Arthur has no clue about SQL. He does not seem to have heard of a basic SQL capability - CTEs (Common Table Expressions) These make it very simple to sequentially process&#x2F;query data.