Sitemap
2 min readDec 4, 2025

--

๐ŸŽฏ ๐’๐๐‹ ๐’๐ž๐ซ๐ข๐ž๐ฌ | ๐„๐ฉ. ๐Ÿ” โ€” ๐‚๐Ž๐”๐๐“, ๐’๐”๐Œ, ๐€๐•๐†, ๐Œ๐ˆ๐, ๐Œ๐€๐— โ€” ๐Œ๐ž๐š๐ฌ๐ฎ๐ซ๐ข๐ง๐  ๐๐ฎ๐ฌ๐ข๐ง๐ž๐ฌ๐ฌ ๐Œ๐ž๐ญ๐ซ๐ข๐œ๐ฌ

๐Ÿ’ฅ ๐‡๐จ๐จ๐ค:
Every metric you see on a business dashboard โ€”
โžก Average session time,
โžก Total orders,
โžก Highest sale,
โžก Number of returning users
all starts with ๐ฃ๐ฎ๐ฌ๐ญ ๐Ÿ๐ข๐ฏ๐ž ๐’๐๐‹ ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ.
๐‚๐Ž๐”๐๐“, ๐’๐”๐Œ, ๐€๐•๐†, ๐Œ๐ˆ๐, ๐Œ๐€๐— โ€” the unsung heroes of data storytelling.

๐Ÿง  ๐‚๐จ๐ง๐œ๐ž๐ฉ๐ญ ๐’๐ข๐ฆ๐ฉ๐ฅ๐ข๐Ÿ๐ข๐ž๐:
When we use SQL to answer questions like:
โžก How long does a user stay on our platform?
or
โžก Whatโ€™s the total revenue by product category?

Weโ€™re using ๐š๐ ๐ ๐ซ๐ž๐ ๐š๐ญ๐ข๐จ๐ง โ€” summarizing detailed data into meaningful metrics. Thatโ€™s where these ๐Ÿ๐ข๐ฏ๐ž ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ come in: ๐‚๐Ž๐”๐๐“, ๐’๐”๐Œ, ๐€๐•๐†, ๐Œ๐ˆ๐, ๐Œ๐€๐—

๐Ÿ’ผ ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž: ๐Œ๐ž๐š๐ฌ๐ฎ๐ซ๐ข๐ง๐  ๐€๐ฏ๐ž๐ซ๐š๐ ๐ž ๐’๐ž๐ฌ๐ฌ๐ข๐จ๐ง ๐“๐ข๐ฆ๐ž (https://lnkd.in/eT57St36)

๐๐ฎ๐ฌ๐ข๐ง๐ž๐ฌ๐ฌ ๐๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง:
How long does an average user spend in one session?

๐Ÿ’ก ๐’๐๐‹ ๐’๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง:

WITH session_times AS (
SELECT
user_id,
DATE(timestamp) AS session_date,
MAX(CASE WHEN action = โ€˜page_loadโ€™ THEN timestamp END) AS load_time,
MIN(CASE WHEN action = โ€˜page_exitโ€™ THEN timestamp END) AS exit_time
FROM facebook_web_log
GROUP BY user_id, DATE(timestamp) )

Get Somyaguptaโ€™s stories inย yourย inbox

Join Medium for free to get updates fromย thisย writer.

SELECT
user_id,
AVG(EXTRACT(EPOCH FROM (exit_time โ€” load_time))) AS avg_session_minutes
FROM session_times
WHERE load_time < exit_time
GROUP BY user_id;

๐Ÿ” ๐’๐ญ๐ž๐ฉ-๐›๐ฒ-๐’๐ญ๐ž๐ฉ ๐‹๐จ๐ ๐ข๐œ:

1. ๐ˆ๐๐ž๐ง๐ญ๐ข๐Ÿ๐ฒ each userโ€™s latest page_load and earliest page_exit per day.
2. ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž session duration in seconds.
3. ๐€๐ฏ๐ž๐ซ๐š๐ ๐ž these durations across all sessions per user.
โžก ๐€๐•๐†() turns multiple session durations into one business KPI: average time spent per user.

๐ŸŒ ๐–๐ก๐ฒ ๐ˆ๐ญ ๐Œ๐š๐ญ๐ญ๐ž๐ซ๐ฌ:

In real-world analytics:
1. ๐„-๐œ๐จ๐ฆ๐ฆ๐ž๐ซ๐œ๐ž โ†’ ๐€๐•๐†(๐ฌ๐ž๐ฌ๐ฌ๐ข๐จ๐ง_๐ญ๐ข๐ฆ๐ž) helps track engagement.
2. ๐๐ซ๐จ๐๐ฎ๐œ๐ญ ๐ญ๐ž๐š๐ฆ๐ฌ โ†’ ๐’๐”๐Œ(๐ฌ๐ž๐ฌ๐ฌ๐ข๐จ๐ง_๐ญ๐ข๐ฆ๐ž) gives total platform usage.
Itโ€™s not just numbers โ€” itโ€™s behavior translated into insights.

๐Ÿงฉ ๐“๐ซ๐ฒ ๐’๐ข๐ฆ๐ข๐ฅ๐š๐ซ ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ๐ฌ:

1๏ธโƒฃ ๐๐ž๐ญ ๐๐ž๐ฐ ๐๐ซ๐จ๐๐ฎ๐œ๐ญ๐ฌ ๐‹๐š๐ฎ๐ง๐œ๐ก๐ž๐ โ€” https://lnkd.in/e_GK9KaA
2๏ธโƒฃ ๐๐ฎ๐ฆ๐›๐ž๐ซ ๐จ๐Ÿ ๐”๐ง๐ข๐ช๐ฎ๐ž ๐’๐ฎ๐›๐ฃ๐ž๐œ๐ญ๐ฌ ๐“๐š๐ฎ๐ ๐ก๐ญ ๐›๐ฒ ๐„๐š๐œ๐ก ๐“๐ž๐š๐œ๐ก๐ž๐ซ โ€” https://lnkd.in/esSF5pYM

๐Ÿ”ฅ ๐‚๐จ๐ฆ๐ข๐ง๐  ๐ฎ๐ฉ ๐ง๐ž๐ฑ๐ญ: ๐„๐ฉ. ๐Ÿ• โ€” ๐†๐‘๐Ž๐”๐ ๐๐˜ & ๐ƒ๐ˆ๐’๐“๐ˆ๐๐‚๐“: ๐”๐ง๐๐ž๐ซ๐ฌ๐ญ๐š๐ง๐๐ข๐ง๐  ๐”๐ง๐ข๐ช๐ฎ๐ž๐ง๐ž๐ฌ๐ฌ ๐ข๐ง ๐ƒ๐š๐ญ๐š

Whatโ€™s one business metric youโ€™ve recently calculated using COUNT, SUM, or AVG?
Share it below ๐Ÿ‘‡ โ€” letโ€™s see how you measure success with SQL.

--

--