
- Main
- Catalog
- Computer science
- Data Analytics - SQL, Python, Excel, AI & ChatGPT
Data Analytics - SQL, Python, Excel, AI & ChatGPT
Global English-speaking audience in this telegram channel who are interested in learning about new things and data oriented stuff.
Channel statistics
WITH cte_name AS (
SELECT ...
)
SELECT * FROM cte_name;
{}
🎯 3. Simple Example
👉 Get employees with salary > 50k
WITH high_salary AS (
SELECT * FROM employees
WHERE salary > 50000
)
SELECT * FROM high_salary;
{}
✔ Makes query more readable
🔥 4. CTE with Aggregation
👉 Average salary per department
WITH dept_avg AS (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT * FROM dept_avg;
{}
⚡ 5. CTE vs Subquery
CTE ->
More readable, Reusable Better for complex queries
Subquery -> Hard to read Not reusable
🎯 6. Real Example (Interview Level)
👉 Employees earning above department average
WITH dept_avg AS (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT e.name, e.salary, e.department
FROM employees e
JOIN dept_avg d
ON e.department = d.department
WHERE e.salary > d.avg_salary;
{}
🎯 7. Practice Tasks
1. Create CTE for employees with salary > 40k
2. Find average salary using CTE
3. Get employees above average salary using CTE
4. Count employees per department using CTE
5. Find highest salary per department using CTE
🔥 Here are the solutions for CTE practice tasks
✅ 1. Create CTE for employees with salary > 40k
WITH high_salary AS (
SELECT * FROM employees
WHERE salary > 40000
)
SELECT * FROM high_salary;
{}
✅ 2. Find average salary using CTE
WITH avg_sal AS (
SELECT AVG(salary) AS avg_salary FROM employees
)
SELECT * FROM avg_sal;
{}
✅ 3. Get employees above average salary using CTE
WITH avg_sal AS (
SELECT AVG(salary) AS avg_salary FROM employees
)
SELECT e.*
FROM employees e, avg_sal a
WHERE e.salary > a.avg_salary;
{}
👉 Alternative (JOIN style):
WITH avg_sal AS (
SELECT AVG(salary) AS avg_salary FROM employees
)
SELECT e.*
FROM employees e
JOIN avg_sal a
ON e.salary > a.avg_salary;
{}
✅ 4. Count employees per department using CTE
WITH dept_count AS (
SELECT department, COUNT(*) AS total_emp
FROM employees
GROUP BY department
)
SELECT * FROM dept_count;
{}
✅ 5. Find highest salary per department using CTE
WITH max_sal AS (
SELECT department, MAX(salary) AS max_salary
FROM employees
GROUP BY department
)
SELECT * FROM max_sal;
{}
⚡ Mini Challenge 🔥
👉 Find top 2 highest salary employees per department using CTE
⚡ Mini Challenge Solution 🔥
WITH ranked_emp AS (
SELECT name, department, salary,
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rn
FROM employees
)
SELECT * FROM ranked_emp
WHERE rn <= 2;
{}
🔥 Pro Tip:
Whenever query looks messy:
👉 Replace subquery with CTE
Double Tap ❤️ For MoreReviews channel
7 total reviews
- Added: Newest first
- Added: Oldest first
- Rating: High to low
- Rating: Low to high
Catalog of Telegram Channels for Native Placements
Data Analytics - SQL, Python, Excel, AI & ChatGPT is a Telegram channel in the category «Интернет технологии», offering effective formats for placing advertising posts on TG. The channel has 109K subscribers and provides quality content. The advertising posts on the channel help brands attract audience attention and increase reach. The channel's rating is 17.8, with 7 reviews and an average score of 5.0.
You can launch an advertising campaign through the Telega.in service, choosing a convenient format for placement. The Platform provides transparent cooperation conditions and offers detailed analytics. The placement cost is 76.8 ₽, and with 44 completed requests, the channel has established itself as a reliable partner for advertising on Telegram. Place integrations today and attract new clients!
You will be able to add channels from the catalog to the cart again.
Комментарий