SQL | Data Analytics | AI
1.9K subscribers
97 photos
9 files
66 links
SQL, Big Query, Looker and DBT for Data Analytics.

https://medium.com/@khavanski
Download Telegram
๐Ÿ“Š Decoding Business Metrics: Median vs. Average! ๐Ÿง

Ever wondered whether to use the average (mean) or the median when presenting your business data? ๐Ÿค”

While the average is a common go-to (add everything up and divide by the count ๐Ÿ”ข), it can sometimes paint a misleading picture, especially when your data has some serious outliers! ๐Ÿ˜ฌ

Think about it: Imagine a company's sales team where a few top performers have HUGE numbers, while the majority have more moderate results. The average might be inflated by those high-flyers, not truly reflecting the typical sales performance. ๐Ÿ“ˆ

โžก๏ธ That's where the median shines! โœจ The median is the middle value when your data is ordered. It's not affected by extreme highs or lows, giving you a more accurate representation of the "typical" data point. ๐ŸŽฏ

When might the median be your MVP? ๐Ÿ‘‡
* ๐Ÿ’ฐ Salary distributions: A few executive salaries can heavily skew the average. The median gives a better sense of the typical employee's earnings.
* ๐Ÿ˜๏ธ Real estate prices: One or two ultra-luxury homes won't drastically impact the median price in an area.
* ๐Ÿ›’ Customer spending: A few very large purchases might inflate the average order value, while the median shows the more common spending amount.

So, next time you're presenting business metrics, take a moment to consider your data's distribution. If you suspect skewness, the median might be your secret weapon for a more truthful and insightful representation! ๐Ÿ’ก

#dataanalyst
๐Ÿ‘6
๐Ÿ“– Visualizing a SQL query
๐Ÿ‘8โค5
๐Ÿ“– Starter Kit 2025 - Data Analyst
๐Ÿ‘5โค3๐Ÿ”ฅ1
๐ŸŽฏ How do you grow from Junior to Senior as an Analytics Engineer?
Itโ€™s not just about writing better SQL โ€” itโ€™s about evolving your mindset and ownership at each level.

Here's a 3-stage roadmap I use to break it down:

๐Ÿ”น Level 1: Junior
Learn foundational tools, build confidence, and write clean code with guidance.
๐Ÿ”ธ Level 2: Mid-Level
Own pipelines and metrics, design reliable dbt models, and support business analysts.
๐Ÿ”ด Level 3: Senior
Architect scalable systems, champion data quality, and shape the teamโ€™s data strategy.

#sql #dataanalyst #Analytics
โค4๐Ÿ”ฅ4๐Ÿ‘1
SQL Interview Questions

1. How would you find duplicate records in SQL?
2.What are various types of SQL joins?
3.What is a trigger in SQL?
4.What are different DDL,DML commands in SQL?
5.What is difference between Delete, Drop and Truncate?
6.What is difference between Union and Union all?
7.Which command give Unique values?
8. What is the difference between Where and Having Clause?
9.Give the execution of keywords in SQL?
10. What is difference between IN and BETWEEN Operator?
11. What is primary and Foreign key?
12. What is an aggregate Functions?
13. What is the difference between Rank and Dense Rank?
14. List the ACID Properties and explain what they are?
15. What is the difference between % and _ in like operator?
16. What does CTE stands for?
17. What is database?what is DBMS?What is RDMS?
18.What is Alias in SQL?
19. What is Normalisation?Describe various form?
20. How do you sort the results of a query?
21. Explain the types of Window functions?
22. What is limit and offset?
23. What is candidate key?
24. Describe various types of Alter command?
25. What is Cartesian product?

Like this post if you need more content like this โค๏ธ
โค4๐Ÿ‘4๐Ÿ”ฅ2
๐Ÿ“Œ SQL Cheatsheet โ€” Quick Reference Guide

Whether youโ€™re just starting out with databases or you need a handy reminder while coding, keep this sheet in your pocket and query with confidence!

---

-- 1๏ธโƒฃ  Database Basics
CREATE DATABASE db_name;
USE db_name;

-- 2๏ธโƒฃ Tables
CREATE TABLE table_name (col1 datatype, col2 datatype);
DROP TABLE table_name;
ALTER TABLE table_name ADD column_name datatype;

-- 3๏ธโƒฃ Insert Data
INSERT INTO table_name (col1, col2) VALUES (val1, val2);

-- 4๏ธโƒฃ Select Queries
SELECT * FROM table_name;
SELECT col1, col2 FROM table_name;
SELECT * FROM table_name WHERE condition;

-- 5๏ธโƒฃ Update Data
UPDATE table_name SET col1 = value1 WHERE condition;

-- 6๏ธโƒฃ Delete Data
DELETE FROM table_name WHERE condition;

-- 7๏ธโƒฃ Joins
SELECT * FROM table1
INNER JOIN table2 ON table1.col = table2.col;
SELECT * FROM table1
LEFT JOIN table2 ON table1.col = table2.col;
SELECT * FROM table1
RIGHT JOIN table2 ON table1.col = table2.col;

-- 8๏ธโƒฃ Aggregations
SELECT COUNT(*) FROM table_name;
SELECT SUM(col) FROM table_name;
SELECT col, COUNT(*) FROM table_name GROUP BY col;

-- 9๏ธโƒฃ Sorting & Limiting
SELECT * FROM table_name ORDER BY col ASC; -- or DESC
SELECT * FROM table_name LIMIT n;

-- ๐Ÿ”Ÿ Indexes
CREATE INDEX idx_name ON table_name (col);
DROP INDEX idx_name;

-- 1๏ธโƒฃ1๏ธโƒฃ Subqueries
SELECT * FROM table_name
WHERE col IN (SELECT col FROM other_table);

-- 1๏ธโƒฃ2๏ธโƒฃ Views
CREATE VIEW view_name AS
SELECT * FROM table_name;
DROP VIEW view_name;
๐Ÿ‘15โค4๐Ÿ”ฅ1
๐Ÿš€ Excel vs SQL vs Python (Pandas):

1๏ธโƒฃ Filtering Data
โ†ณ Excel: =FILTER(A2:D100, B2:B100>50) (Excel 365 users)
โ†ณ SQL: SELECT * FROM table WHERE column > 50;
โ†ณ Python: df_filtered = df[df['column'] > 50]

2๏ธโƒฃ Sorting Data
โ†ณ Excel: Data โ†’ Sort (or =SORT(A2:A100, 1, TRUE))
โ†ณ SQL: SELECT * FROM table ORDER BY column ASC;
โ†ณ Python: df_sorted = df.sort_values(by="column")

3๏ธโƒฃ Counting Rows
โ†ณ Excel: =COUNTA(A:A)
โ†ณ SQL: SELECT COUNT(*) FROM table;
โ†ณ Python: row_count = len(df)

4๏ธโƒฃ Removing Duplicates
โ†ณ Excel: Data โ†’ Remove Duplicates
โ†ณ SQL: SELECT DISTINCT * FROM table;
โ†ณ Python: df_unique = df.drop_duplicates()

5๏ธโƒฃ Joining Tables
โ†ณ Excel: Power Query โ†’ Merge Queries (or VLOOKUP/XLOOKUP)
โ†ณ SQL: SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;
โ†ณ Python: df_merged = pd.merge(df1, df2, on="id")

6๏ธโƒฃ Ranking Data
โ†ณ Excel: =RANK.EQ(A2, $A$2:$A$100)
โ†ณ SQL: SELECT column, RANK() OVER (ORDER BY column DESC) AS rank FROM table;
โ†ณ Python: df["rank"] = df["column"].rank(method="min", ascending=False)

7๏ธโƒฃ Moving Average Calculation
โ†ณ Excel: =AVERAGE(B2:B4) (manually for rolling window)
โ†ณ SQL: SELECT date, AVG(value) OVER (ORDER BY date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_avg FROM table;
โ†ณ Python: df["moving_avg"] = df["value"].rolling(window=3).mean()

8๏ธโƒฃ Running Total
โ†ณ Excel: =SUM($B$2:B2) (drag down)
โ†ณ SQL: SELECT date, SUM(value) OVER (ORDER BY date) AS running_total FROM table;
โ†ณ Python: df["running_total"] = df["value"].cumsum()
โค14๐Ÿ‘6
๐Ÿ’ป How Do Analysts Use SQL in a Company?

SQL is every data analystโ€™s *superpower* ๐Ÿ’ฅ
Hereโ€™s how it's used in the real world:

๐Ÿ” Extract Data
Pull info from multiple tables to answer real business questions.

SELECT name, revenue FROM sales WHERE region = 'North America';


(P.S. Say NO to `SELECT *`โ€”your future self will thank you!)

๐Ÿงน Clean & Transform
Use functions like TRIM(), COALESCE(), CAST() to tidy up raw data.

๐Ÿ“Š Summarize & Analyze
Find trends with GROUP BY, SUM(), AVG() and more.

๐Ÿ“ˆ Build Dashboards
Plug your queries into Power BI, Tableau, or Excel to tell visual stories.

๐Ÿงช Run A/B Tests
Measure product changes and campaigns with data, not guesses.

๐Ÿงฑ Use Views & CTEs
Simplify complex logic. Clean. Reusable. Boss-approved.

๐ŸŽฏ Drive Decisions
Marketing, Product, Sales, Financeโ€”SQL helps *everyone* answer:
โ€œWhatโ€™s working?โ€

๐Ÿ’ก Write *smart* queries.
Avoid SELECT * unless you really, *really* mean it.
โค7๐Ÿ”ฅ2
SQL Interview Questions with Answers

1. How to change a table name in SQL?
This is the command to change a table name in SQL:
ALTER TABLE table_name
RENAME TO new_table_name;
We will start off by giving the keywords ALTER TABLE, then we will follow it up by giving the original name of the table, after that, we will give in the keywords RENAME TO and finally, we will give the new table name.

2. How to use LIKE in SQL?
The LIKE operator checks if an attribute value matches a given string pattern. Here is an example of LIKE operator
SELECT * FROM employees WHERE first_name like โ€˜Stevenโ€™;
With this command, we will be able to extract all the records where the first name is like โ€œStevenโ€.

3. If we drop a table, does it also drop related objects like constraints, indexes, columns, default, views and sorted procedures?
Yes, SQL server drops all related objects, which exists inside a table like constraints, indexes, columns, defaults etc. But dropping a table will not drop views and sorted procedures as they exist outside the table.

4. Explain SQL Constraints.
SQL Constraints are used to specify the rules of data type in a table. They can be specified while creating and altering the table. The following are the constraints in SQL: NOT NULL CHECK DEFAULT UNIQUE PRIMARY KEY FOREIGN KEY

React โค๏ธ for more
โค7๐Ÿ‘1
Little tip to handle data quality issues

#sql #bigquery
๐Ÿ‘6๐Ÿ”ฅ1
๐Ÿ“– SQL For Everything
โค2
Must-know Pandas Functions for Data Analysis
๐Ÿ‘5โค4
Here is a powerful ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ฉ๐—œ๐—˜๐—ช ๐—ง๐—œ๐—ฃ to help you land a job!

Most people who are skilled enough would be able to clear technical rounds with ease.

But when it comes to ๐—ฏ๐—ฒ๐—ต๐—ฎ๐˜ƒ๐—ถ๐—ผ๐—ฟ๐—ฎ๐—น/๐—ฐ๐˜‚๐—น๐˜๐˜‚๐—ฟ๐—ฒ ๐—ณ๐—ถ๐˜ rounds, some folks may falter and lose the potential offer.

Many companies schedule a behavioral round with a top-level manager in the organization to understand the culture fit (except for freshers).

One needs to clear this round to reach the salary negotiation round.

Here are some tips to clear such rounds:

1๏ธโƒฃ Once the HR schedules the interview, try to find the LinkedIn profile of the interviewer using the name in their email ID.

2๏ธโƒฃ Learn more about his/her past experiences and try to strike up a conversation on that during the interview.

3๏ธโƒฃ This shows that you have done good research and also helps strike a personal connection.

4๏ธโƒฃ Also, this is the round not just to evaluate if you're a fit for the company, but also to assess if the company is a right fit for you.

5๏ธโƒฃ Hence, feel free to ask many questions about your role and company to get a clear understanding before taking the offer. This shows that you really care about the role you're getting into.
โค4
SQL โ‡† Python โ‡† Excel
โค8๐Ÿ‘2๐Ÿ‘2๐Ÿคฏ1
โœ…SQL Checklist for Data Analysts ๐Ÿ“€๐Ÿง 
1. SQL Basicsโฆ SELECT, WHERE, ORDER BY
โฆ DISTINCT, LIMIT, BETWEEN, INโฆ Aliasing (AS)
2. Filtering & Aggregation
โฆ GROUP BY & HAVINGโฆ COUNT(), SUM(), AVG(), MIN(), MAX()
โฆ NULL handling with COALESCE, IS NULL

3. Joins
โฆ INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN
โฆ Joining multiple tables
โฆ Self Joins

4. Subqueries & CTEs
โฆ Subqueries in SELECT, WHERE, FROM
โฆ WITH clause (Common Table Expressions)
โฆ Nested subqueries

5. Window Functions
โฆ ROW_NUMBER(), RANK(), DENSE_RANK()
โฆ LEAD(), LAG()
โฆ PARTITION BY & ORDER BY within OVER()

6. Data Manipulation
โฆ INSERT, UPDATE, DELETE
โฆ CREATE TABLE, ALTER TABLE
โฆ Constraints: PRIMARY KEY, FOREIGN KEY, NOT NULL

7. Optimization Techniques
โฆ Indexes
โฆ Query performance tips
โฆ EXPLAIN plans

8. Real-World Scenarios
โฆ Writing complex queries for reports
โฆ Customer, sales, and product data
โฆ Time-based analysis (e.g., monthly trends)

9. Tools & Practice Platforms
โฆ MySQL, PostgreSQL, SQL Server
โฆ DB Fiddle, Mode Analytics, LeetCode (SQL), StrataScratch

10. Portfolio & Projects
โฆ Showcase queries on GitHub
โฆ Analyze public datasets (e.g., ecommerce, finance)
โฆ Document business insights
โค6
Why Do Investors Care So Much About LTV:CAC?


https://a16z.com/why-do-investors-care-so-much-about-ltvcac
โค6
Recursive CTE in SQL
โค6๐Ÿ‘2๐Ÿ‘1
๐Ÿš€ Essential SaaS Metrics: What Really Matters?

A SaaS business runs on subscriptions.
Its health = predictable revenue + strong retention + efficient growth.

Here are the core metrics every SaaS founder, operator, and investor should track.

---

## ๐Ÿ’ฐ Core Financial Metrics

๐Ÿ”น MRR / ARR โ€” Monthly / Annual Recurring Revenue
Your primary indicator of predictable revenue.

๐Ÿ”น ARPU โ€” Average Revenue Per User
How much revenue each customer generates on average.

๐Ÿ”น ARR Growth Rate โ€” Percentage increase in ARR
Shows how fast the company is scaling.

๐Ÿ”น Expansion Revenue โ€” Upsells, upgrades, add-ons
The healthiest form of growth comes from existing customers.

๐Ÿ”น Gross Profit Margin
Revenue minus cost of goods sold. Strong SaaS businesses typically operate at 70โ€“90%.

---

## ๐Ÿ” Retention & Customer Success Metrics

๐Ÿ”น Churn Rate (Logo & Revenue)
Percentage of customers or revenue lost during a period. Lower = stronger stability.

๐Ÿ”น Net Dollar Retention (NDR / NRR)
Revenue retained from existing customers including upgrades/downgrades.
If >100%, your revenue grows even without acquiring new customers.

๐Ÿ”น NPS (Net Promoter Score)
Measures customer loyalty and likelihood to recommend.

๐Ÿ”น Usage / Activation Rate
How actively customers use your product. Low usage today = churn tomorrow.

---

## ๐Ÿ“ˆ Acquisition & Efficiency Metrics

๐Ÿ”น CAC (Customer Acquisition Cost)
Total sales & marketing spend required to acquire a new customer.

๐Ÿ”น LTV / CLV (Customer Lifetime Value)
Total revenue expected from a customer over their lifecycle.

๐Ÿ”น LTV-to-CAC Ratio
Measures ROI on acquisition. Ideal benchmark: 3:1 or higher.

๐Ÿ”น CAC Payback Period
Months required to recover acquisition costs. Ideally < 12 months.

๐Ÿ”น Rule of 40
Revenue growth rate + profit margin should exceed 40%.
A strong benchmark for balanced growth.

---

## ๐Ÿ”ฅ Additional Stability Metrics

โ€ข Cash Runway โ€” How long the company can operate before running out of cash
โ€ข Customer Concentration โ€” Revenue dependence on a few major customers
โ€ข Burn Multiple โ€” Efficiency of growth relative to cash burned

---

๐Ÿ“Œ SaaS isnโ€™t just about growth.
Itโ€™s about *predictable, efficient, and sustainable growth.*

Track the right metrics. Build with discipline. Scale with confidence.
โค5
SQL execution order๐Ÿ“ˆ

One day at an interview you will be asked this question
โค4๐Ÿ‘2