๐ฏ ๐๐๐ ๐๐๐ซ๐ข๐๐ฌ | ๐๐ฉ. ๐ โ ๐๐๐๐๐, ๐๐๐, ๐๐๐, ๐๐๐, ๐๐๐ โ ๐๐๐๐ฌ๐ฎ๐ซ๐ข๐ง๐ ๐๐ฎ๐ฌ๐ข๐ง๐๐ฌ๐ฌ ๐๐๐ญ๐ซ๐ข๐๐ฌ
๐ฅ ๐๐จ๐จ๐ค:
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.






