Data Analytics
Perfect channel to learn Data Analytics Learn SQL, Python, Alteryx, Tableau, Power BI and many more For Promotions: @coderfun @love_data
Ko'proq ko'rsatish📈 Telegram kanali Data Analytics analitikasi
Data Analytics (@sqlspecialist) Ingliz til segmentidagi kanali faol ishtirokchi. Hozirda hamjamiyat 110 825 obunachidan iborat bo'lib, Texnologiyalar & Aralashmalar toifasida 1 062-o'rinni va Hindiston mintaqasida 2 202-o'rinni egallagan.
📊 Auditoriya ko‘rsatkichlari va dinamika
невідомо sanasidan buyon loyiha tez o‘sib, 110 825 obunachiga ega bo‘ldi.
14 Sentabr, 2026 dagi oxirgi ma’lumotlarga ko‘ra kanal barqaror faollikka ega. Oxirgi 30 kunda obunachilar soni 121 ga, so‘nggi 24 soatda esa 1 ga o‘zgardi va umumiy qamrov yuqori darajada qolmoqda.
- Tasdiqlash holati: Tasdiqlanmagan
- Jalb etish (ER): Auditoriya o‘rtacha 2.27% darajada jalb etiladi. Nashrdan keyingi dastlabki 24 soatda kontent odatda umumiy obunachilar sonining 1.14% ini tashkil etuvchi reaksiyalarni to‘playdi.
- Post qamrovi: Har bir post o‘rtacha 2 520 marta ko‘riladi; birinchi sutkada odatda 1 269 ta ko‘rish yig‘iladi.
- Reaksiyalar va o‘zaro ta’sir: Auditoriya faol: har bir postga o‘rtacha 5 ta reaksiya keladi.
- Tematik yo‘nalishlar: Kontent row, sql, analytic, analyst, visualization kabi asosiy mavzularga jamlangan.
📝 Tavsif va kontent siyosati
Muallif resursni shaxsiy fikrni ifoda etish maydoni sifatida ta’riflaydi:
“Perfect channel to learn Data Analytics
Learn SQL, Python, Alteryx, Tableau, Power BI and many more
For Promotions: @coderfun @love_data”
Yuqori yangilanish chastotasi (oxirgi ma’lumot 15 Sentabr, 2026 da olingan) sababli kanal doimo dolzarb va katta qamrovli bo‘lib qoladi. Analitika auditoriya kontent bilan faol hamkorlik qilishini, uni Texnologiyalar & Aralashmalar toifasidagi muhim ta’sir nuqtasiga aylantirishini ko‘rsatadi.
Customers
Products ──── Sales ──── Date
Region
The fact table is in the middle and dimension tables surround it.
This is called a Star Schema.
🔹 5. Primary Key
A primary key uniquely identifies a record.
For example:
Customer_ID
101
102
103
Each ID identifies one customer.
🔹 6. Foreign Key
The Sales table can contain the same customer multiple times:
Customer_ID
101
101
102
101
103
Here, "Customer_ID" is used to connect Sales with Customers.
So:
Customers → Primary Key
Sales → Foreign Key
🔹 7. One-to-Many Relationship
The most common relationship in Power BI is:
One Customer → Many Sales
Customers Sales
1 *
| |
Customer_ID ───────── Customer_ID
This is called a:
1 : * relationship
🔹 8. Why Relationships Matter
Suppose you select:
Region = West
Power BI needs to know which sales belong to customers from the West region.
The relationship allows the filter to travel from:
Customers
↓
Sales
Without a proper relationship, your visuals may show incorrect results.
🔹 9. Cardinality
Cardinality describes how records relate between two tables.
Common types:
1 : * → One-to-Many
1 : 1 → One-to-One
• : * → Many-to-Many
For most Power BI analytical models, 1-to-many relationships are the most common.
🔹 10. Many-to-Many Relationships
Many-to-many relationships can make models more complicated.
For example:
Customers ↔ Products
A customer can buy many products.
A product can be purchased by many customers.
Instead of directly connecting them in some cases, a bridge table can be used.
Customers
↓
Bridge Table
↓
Products
🔹 11. Date Table
A proper Date table is extremely important for Power BI.
It can contain:
Date
Day
Month
Month Number
Quarter
Year
Year-Month
For example:
Date | Month | Quarter | Year
01-Jan-26 | January | Q1 | 2026
02-Jan-26 | January | Q1 | 2026(Total_Sales - Previous_Sales) / NULLIF(Previous_Sales, 0) * 100
NULLIF() prevents division-by-zero errors.
🔹 12. Find the Latest Order for Every Customer
WITH Ranked_Orders AS (
SELECT Customer_ID, Order_ID, Order_Date,
ROW_NUMBER() OVER (PARTITION BY Customer_ID ORDER BY Order_Date DESC) AS rn
FROM Orders
)
SELECT Customer_ID, Order_ID, Order_Date FROM Ranked_Orders WHERE rn = 1;
🔹 13-14. Inactive Customers & Duplicates
Inactive = MAX(Order_Date) vs 90-day threshold.
Business defines the rule, SQL calculates it.
Detect duplicates:
WITH Duplicate_Check AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY Customer_ID, Order_Date, Sales ORDER BY Order_ID) AS rn
FROM Orders
)
SELECT * FROM Duplicate_Check WHERE rn > 1;
🔹 15. Combining Multiple Tables
SELECT c.Customer_ID, c.Customer_Name, p.Product_Name, oi.Quantity, oi.Sales
FROM Customers c
JOIN Orders o ON c.Customer_ID = o.Customer_ID
JOIN Order_Items oi ON o.Order_ID = oi.Order_ID
JOIN Products p ON oi.Product_ID = p.Product_ID;
⚠️ Every additional join can change the number of rows. Always check the grain.
🔹 16. The Most Important Analytical Pattern
1. Filter raw data → 2. Join tables → 3. Aggregate to correct grain → 4. Apply window functions → 5. Filter analytical result → 6. Present final output
💼 Real-World Business Problems to Practice
Sales: Top 5 products by revenue, Top products within each category, Month with highest sales, Revenue growth by month
Customers: Customers with no orders, declining purchases, most recent purchase, repeat customers, AOV per customer
Operations: Orders taking longer than expected, Products never sold, Duplicate transactions, Most active regions
🎯 SQL Interview Challenge: Find the highest-selling product in each category.
WITH Product_Sales AS (
SELECT Product_ID, Category, SUM(Sales) AS Total_Sales
FROM Product_Sales_Data GROUP BY Product_ID, Category
),
Ranked_Products AS (
SELECT *, RANK() OVER (PARTITION BY Category ORDER BY Total_Sales DESC) AS Sales_Rank
FROM Product_Sales
)
SELECT Product_ID, Category, Total_Sales FROM Ranked_Products WHERE Sales_Rank = 1;
🧠 SQL Resources: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
Double Tap ❤️ For More
-----
1.38 ₽ · /balance_helpSELECT
c.Customer_ID,
c.Customer_Name,
SUM(o.Sales) AS Total_Sales
FROM Customers c
JOIN Orders o ON c.Customer_ID = o.Customer_ID
GROUP BY c.Customer_ID, c.Customer_Name;
🔹 4. Rank Customers by Revenue
WITH Customer_Sales AS (
SELECT Customer_ID, SUM(Sales) AS Total_Sales
FROM Orders GROUP BY Customer_ID
)
SELECT
Customer_ID,
Total_Sales,
RANK() OVER (ORDER BY Total_Sales DESC) AS Sales_Rank
FROM Customer_Sales;
🔹 5. Top 3 Customers in Each Region
WITH Customer_Sales AS (
SELECT Customer_ID, Region, SUM(Sales) AS Total_Sales
FROM Orders GROUP BY Customer_ID, Region
),
Ranked_Customers AS (
SELECT *, RANK() OVER (PARTITION BY Region ORDER BY Total_Sales DESC) AS Sales_Rank
FROM Customer_Sales
)
SELECT * FROM Ranked_Customers WHERE Sales_Rank <= 3;
🔹 6. Finding the Second-Highest Salary
WITH Ranked_Employees AS (
SELECT Employee, Salary,
DENSE_RANK() OVER (ORDER BY Salary DESC) AS Salary_Rank
FROM Employees
)
SELECT Employee, Salary FROM Ranked_Employees WHERE Salary_Rank = 2;
🔹 7. Find Products That Never Sold
SELECT p.Product_ID, p.Product_Name
FROM Products p
LEFT JOIN Order_Items oi ON p.Product_ID = oi.Product_ID
WHERE oi.Product_ID IS NULL;
🔹 8. Customers With No Orders
SELECT c.Customer_ID, c.Customer_Name
FROM Customers c
LEFT JOIN Orders o ON c.Customer_ID = o.Customer_ID
WHERE o.Customer_ID IS NULL;
🔹 9. Customers Above Average Spending
WITH Customer_Sales AS (
SELECT Customer_ID, SUM(Sales) AS Total_Sales
FROM Orders GROUP BY Customer_ID
)
SELECT Customer_ID, Total_Sales FROM Customer_Sales
WHERE Total_Sales > (SELECT AVG(Total_Sales) FROM Customer_Sales);
🔹 10. Month-over-Month Sales Growth
WITH Monthly_Sales AS (
SELECT EXTRACT(YEAR FROM Order_Date) AS Year,
EXTRACT(MONTH FROM Order_Date) AS Month,
SUM(Sales) AS Total_Sales
FROM Orders GROUP BY 1, 2
),
Comparison AS (
SELECT Year, Month, Total_Sales,
LAG(Total_Sales) OVER (ORDER BY Year, Month) AS Previous_Sales
FROM Monthly_Sales
)
SELECT Year, Month, Total_Sales, Previous_Sales,
Total_Sales - Previous_Sales AS Sales_Change
FROM Comparison;SELECT Customer_ID, SUM(Sales) / COUNT(DISTINCT Order_ID) AS AOV
FROM Orders GROUP BY Customer_ID;
This tells us how much a customer spends per order on average.
🔹 12. Purchase Frequency
We can also calculate the number of orders per customer:
SELECT Customer_ID, COUNT(DISTINCT Order_ID) AS Number_of_Orders
FROM Orders GROUP BY Customer_ID;
Customers can then be segmented based on activity.
For example:
• 1 order → One-time customer
• 2–5 orders → Repeat customer
• 6+ orders → Highly active customer
⚠️ These thresholds are business rules, not universal definitions.
🔹 13. Recency
SELECT Customer_ID, MAX(Order_Date) AS Last_Order_Date
FROM Orders GROUP BY Customer_ID;
Then compare the last order date with a chosen analysis date.
A customer who purchased recently is generally more active than someone whose last purchase was a long time ago.
🔹 14. RFM Analysis
• R → Recency: How recently?
• F → Frequency: How often?
• M → Monetary: How much?
Example:
Customer | Recency | Frequency | Monetary
C101 | 5 days | 12 orders | ₹85,000
C102 | 20 days | 6 orders | ₹42,000
C103 | 120 days| 2 orders | ₹8,000
This allows businesses to identify:
⭐ High-value customers
🔄 Loyal customers
⚠️ Customers at risk
💤 Inactive customers
🔹 15. Segmentation With CASE
You can convert analytical metrics into business segments.
For example:
SELECT Customer_ID, Total_Sales,
CASE
WHEN Total_Sales >= 50000 THEN 'High Value'
WHEN Total_Sales >= 20000 THEN 'Medium Value'
ELSE 'Low Value'
END AS Customer_Segment
FROM Customer_Sales;
This transforms numerical analysis into a business-friendly classification.
🔹 16. Repeat Customers
SELECT Customer_ID, COUNT(DISTINCT Order_ID) AS Order_Count
FROM Orders GROUP BY Customer_ID
HAVING COUNT(DISTINCT Order_ID) > 1;
This finds customers with more than one order.
🔹 17. First vs Repeat Purchase
You can use ROW_NUMBER() to identify purchase sequence.
WITH Customer_Orders AS (
SELECT Customer_ID, Order_ID, Order_Date,
ROW_NUMBER() OVER (PARTITION BY Customer_ID ORDER BY Order_Date) AS Purchase_Number
FROM Orders
)
SELECT * FROM Customer_Orders;
Now:
Purchase_Number = 1 means the customer's first purchase.
Purchase_Number = 2 means the second purchase.
And so on.
This opens the door to deeper customer behavior analysis.
🔹 18. Time Between Purchases
SELECT Customer_ID, Order_Date,
LAG(Order_Date) OVER (PARTITION BY Customer_ID ORDER BY Order_Date) AS Previous_Order_Date
FROM Orders;
Now you can calculate the number of days between purchases.
→ Helps answer "How frequently do customers return?"
🔹 19. Churn Analysis
Churn means customers stop using or purchasing from a business.
SQL can help identify customers whose activity has fallen below a defined threshold.
For example:
Last Purchase → Days Since → Business Threshold → Active / At Risk / Inactive
SQL finds pattern, business defines churn.
🎯 Interview Challenge
Find customers with ≥3 orders and >50,000 spent:
SELECT Customer_ID, COUNT(DISTINCT Order_ID) AS Order_Count, SUM(Sales) AS Total_Sales
FROM Orders
GROUP BY Customer_ID
HAVING COUNT(DISTINCT Order_ID) >= 3 AND SUM(Sales) > 50000;
🧠 Double Tap ❤️ For More
-----
1.41 ₽ · /balance_helpSELECT
Customer_ID,
MIN(Order_Date) AS First_Order_Date
FROM Orders
GROUP BY Customer_ID;
This gives us the first purchase date for every customer.
Customer | First Order
C101 | 2026-01-10
C102 | 2026-01-18
C103 | 2026-02-05
🔹 4. Step 2 — Assign a Cohort Month
We can convert the first purchase into a month-level cohort.
First Purchase Date → Cohort Month
C101 → 2026-01
C103 → 2026-02
The exact month-truncation syntax varies between SQL databases.
🔹 5. Step 3 — Join Cohort Back to Orders
Now we need both:
Customer's cohort
and
Customer's subsequent activity
WITH Customer_Cohorts AS (
SELECT Customer_ID, MIN(Order_Date) AS First_Order_Date
FROM Orders GROUP BY Customer_ID
)
SELECT o.Customer_ID, c.First_Order_Date, o.Order_Date, o.Sales
FROM Orders o
JOIN Customer_Cohorts c ON o.Customer_ID = c.Customer_ID;
Now every transaction knows which cohort the customer belongs to.
🔹 6. Cohort Month vs Activity Month
• Cohort Month: When first purchased
• Activity Month: When purchase happened
Customer | Cohort | Activity
C101 | Jan | Jan
C101 | Jan | Feb
C101 | Jan | Mar
🔹 7. Measuring Retention
Retention measures how many customers from a cohort remain active in later periods.
Retention = Active in Period / Original Cohort * 100
• Jan cohort: 100 customers
• Feb: 60 active → 60%
• Mar: 40 active → 40%
🔹 8. Retention Month
Months Since Cohort = Activity - Cohort
Eg:
Customer | Cohort | Activity | Months_Since_Cohort
C101 | Jan | Jan | 0
C101 | Jan | Feb | 1
C101 | Jan | Mar | 2
🔹 9. Cohort Retention Matrix
Conceptually, the final result may look like:
Cohort | Month0 | Month1 | Month2 | Month3
Jan | 100% | 60% | 40% | 30%
Feb | 100% | 65% | 45% | —
Mar | 100% | 70% | — | —
This is often called a cohort retention matrix.
It immediately shows whether newer customer cohorts are retaining better or worse.
🔹 10. Customer Lifetime Value (CLV)
Another important customer metric is Customer Lifetime Value (CLV/LTV).
A simplified version can be based on:
Total Revenue Generated by Customer
A more advanced business model may consider:
• Revenue
• Gross margin
• Purchase frequency
• Retention
• Customer lifespan
• Acquisition cost
🔹 11. Average Order Value (AOV)
A basic customer metric is:
Average Order Value = Total Sales ÷ Number of Orders
In SQL:SELECT * FROM Orders WHERE YEAR(Order_Date) = 2026;
How could you improve it?
A better approach is:
SELECT Order_ID, Customer_ID, Order_Date, Sales
FROM Orders
WHERE Order_Date >= '2026-01-01'
AND Order_Date < '2027-01-01';
Why?
✔ Avoids unnecessary columns
✔ Uses a range filter
✔ Can be more index-friendly
✔ Clearly defines the required period
Then use EXPLAIN/EXPLAIN ANALYZE to verify the actual execution plan.
🧠 Double Tap ❤️ For More
-----
1.56 ₽ · /balance_help