๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ฃ๐ผ๐๐ฒ๐ฟ ๐๐ ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐! ๐ฅ
Learn Power BI through these FREE learning resources
โ
โจ What You'll Learn:
๐ Interactive Dashboards
๐ Data Visualization
๐งน Data Transformation
๐ผ Real-World Reporting Skills
๐ฏ Beginner-Friendly โ No Coding Required
๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐
โ
โhttps://pdlink.in/4hznwlu
๐ซPerfect for Students โข Freshers โข Data Analyst Aspirants โข Working Professionals
Learn Power BI through these FREE learning resources
โ
โจ What You'll Learn:
๐ Interactive Dashboards
๐ Data Visualization
๐งน Data Transformation
๐ผ Real-World Reporting Skills
๐ฏ Beginner-Friendly โ No Coding Required
๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐
โ
โhttps://pdlink.in/4hznwlu
๐ซPerfect for Students โข Freshers โข Data Analyst Aspirants โข Working Professionals
โค1
๐๐ฃ๐ฎ๐ ๐๐ณ๐๐ฒ๐ฟ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐ง๐ฟ๐ฎ๐ถ๐ป๐ถ๐ป๐ด | ๐๐ฒ๐ฐ๐ผ๐บ๐ฒ ๐ฎ ๐๐๐น๐น๐๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ ๐ช๐๐๐ต ๐๐ฒ๐ป๐๐
Start a high-paying tech careerโeven without prior coding experience
๐ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ hiring partners
โ 100% job assistance
๐ Skill Indiaโauthenticated certificate
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐๐:-
https://pdlink.in/3SuUeuD
๐ฏ HurryUp.....Limited Seats Available
Start a high-paying tech careerโeven without prior coding experience
๐ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ hiring partners
โ 100% job assistance
๐ Skill Indiaโauthenticated certificate
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐๐:-
https://pdlink.in/3SuUeuD
๐ฏ HurryUp.....Limited Seats Available
โค4
๐ Data Science Roadmap 2026
๐ Phase 3: SQL for Data Science
๐ Topic 4 โ LIMIT
LIMIT is used to control how many rows a SQL query returns.
It is especially useful when you want to see only the first few records, such as:
โข Top 5 highest salaries
โข Top 10 products by sales
โข First 20 customers
โข Latest 10 transactions
๐น Basic Syntax
This returns only 5 rows from the result.
๐น LIMIT with ORDER BY
This is where LIMIT becomes especially powerful.
Suppose you want the 5 highest-paid employees:
The logical idea is:
Filter โ Sort โ Take required number of rows
For example:
Only the top 5 rows are returned.
๐น LIMIT Without ORDER BY
You can write:
But without ORDER BY, you should not assume these are the "first" or "top" 5 meaningful records.
The database does not guarantee a particular order unless you explicitly specify one.
So for analysis, this is usually better:
๐น LIMIT with WHERE
You can combine WHERE, ORDER BY, and LIMIT.
Example:
This finds the 3 highest-paid employees in the IT department.
๐น LIMIT for Top-N Analysis
Top-N queries are extremely common in data analysis.
Top 10 products by sales
5 most recent transactions
3 cheapest products
๐น LIMIT with OFFSET
OFFSET allows you to skip a certain number of rows before returning results.
Example:
This means:
Skip 10 rows
โ
Return the next 5 rows
This is commonly used for pagination.
For example:
โข Page 1 โ
โข Page 2 โ
โข Page 3 โ
Syntax can vary between SQL databases, so always check the specific database you are using.
๐น LIMIT vs TOP vs FETCH
Different SQL databases may use different syntax.
MySQL/PostgreSQL/SQLite commonly use:
SQL Server commonly uses:
Standard SQL also supports:
The concept is the same: restrict the number of returned rows.
๐น Real-World Data Science Example
Suppose an analyst wants to investigate the 10 largest customer transactions.
This can help identify:
โข High-value transactions
โข Potential anomalies
โข Important customers
โข Transactions requiring further investigation
๐น Common Mistakes
Mistake 1 โ Using LIMIT without sorting
This does not necessarily mean "10 best products."
For that:
Mistake 2 โ Using ASC when you need the highest values
Wrong:
This returns the lowest salaries.
For the highest salaries:
๐ Phase 3: SQL for Data Science
๐ Topic 4 โ LIMIT
LIMIT is used to control how many rows a SQL query returns.
It is especially useful when you want to see only the first few records, such as:
โข Top 5 highest salaries
โข Top 10 products by sales
โข First 20 customers
โข Latest 10 transactions
๐น Basic Syntax
SELECT *
FROM employees
LIMIT 5;
This returns only 5 rows from the result.
๐น LIMIT with ORDER BY
This is where LIMIT becomes especially powerful.
Suppose you want the 5 highest-paid employees:
SELECT employee_name, salary
FROM employees
ORDER BY salary DESC
LIMIT 5;
The logical idea is:
Filter โ Sort โ Take required number of rows
For example:
Salary
120000
110000
95000
90000
85000
Only the top 5 rows are returned.
๐น LIMIT Without ORDER BY
You can write:
SELECT *
FROM employees
LIMIT 5;
But without ORDER BY, you should not assume these are the "first" or "top" 5 meaningful records.
The database does not guarantee a particular order unless you explicitly specify one.
So for analysis, this is usually better:
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 5;
๐น LIMIT with WHERE
You can combine WHERE, ORDER BY, and LIMIT.
Example:
SELECT employee_name, salary
FROM employees
WHERE department = 'IT'
ORDER BY salary DESC
LIMIT 3;
This finds the 3 highest-paid employees in the IT department.
๐น LIMIT for Top-N Analysis
Top-N queries are extremely common in data analysis.
Top 10 products by sales
SELECT product_name, sales
FROM products
ORDER BY sales DESC
LIMIT 10;
5 most recent transactions
SELECT transaction_id, transaction_date, amount
FROM transactions
ORDER BY transaction_date DESC
LIMIT 5;
3 cheapest products
SELECT product_name, price
FROM products
ORDER BY price ASC
LIMIT 3;
๐น LIMIT with OFFSET
OFFSET allows you to skip a certain number of rows before returning results.
Example:
SELECT *
FROM employees
LIMIT 5 OFFSET 10;
This means:
Skip 10 rows
โ
Return the next 5 rows
This is commonly used for pagination.
For example:
โข Page 1 โ
LIMIT 10 OFFSET 0โข Page 2 โ
LIMIT 10 OFFSET 10โข Page 3 โ
LIMIT 10 OFFSET 20Syntax can vary between SQL databases, so always check the specific database you are using.
๐น LIMIT vs TOP vs FETCH
Different SQL databases may use different syntax.
MySQL/PostgreSQL/SQLite commonly use:
LIMIT 5;SQL Server commonly uses:
SELECT TOP 5 *
FROM employees;
Standard SQL also supports:
FETCH FIRST 5 ROWS ONLY;The concept is the same: restrict the number of returned rows.
๐น Real-World Data Science Example
Suppose an analyst wants to investigate the 10 largest customer transactions.
SELECT customer_id,
transaction_id,
amount
FROM transactions
ORDER BY amount DESC
LIMIT 10;
This can help identify:
โข High-value transactions
โข Potential anomalies
โข Important customers
โข Transactions requiring further investigation
๐น Common Mistakes
Mistake 1 โ Using LIMIT without sorting
SELECT *
FROM products
LIMIT 10;
This does not necessarily mean "10 best products."
For that:
ORDER BY sales DESC
LIMIT 10;
Mistake 2 โ Using ASC when you need the highest values
Wrong:
ORDER BY salary ASC
LIMIT 5;
This returns the lowest salaries.
For the highest salaries:
โค3
ORDER BY salary DESC
LIMIT 5;
Mistake 3 โ Forgetting that LIMIT applies after sorting
For a top-N analysis, think:
ORDER BY โ LIMITnot simply:
LIMIT โ assume top records๐น Interview Questions
1. What is LIMIT?
LIMIT restricts the number of rows returned by a query.
2. How do you find the top 10 salaries?
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10;
3. Can LIMIT be used with WHERE?
Yes.
SELECT *
FROM employees
WHERE department = 'Finance'
LIMIT 5;
4. Why is ORDER BY important when using LIMIT?
Because without sorting, the returned rows are not necessarily the highest, lowest, newest, or oldest records you want.
5. What is OFFSET used for?
OFFSET skips a specified number of rows before returning the requested rows, commonly for pagination.
๐ฏ Double Tap โค๏ธ For More
โค6
๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ถ๐๐ต ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ฒ๐! ๐๐ฅ
Upgrade your resume with Microsoft learning opportunities. Explore courses covering some of today's most in-demand tech skills!
๐ฏ Perfect for Students โข Freshers โข Job Seekers โข Working Professionals
โ Learn at your own pace โ Build career-relevant skills โ Explore available certificates and credentials
๐ ๐๐ฐ๐ฐ๐ฒ๐๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ฒ๐ฟ๐ฒ ๐
https://pdlink.in/3Uf5trR
๐ฅ Share with friends looking to upskill in 2026!
Upgrade your resume with Microsoft learning opportunities. Explore courses covering some of today's most in-demand tech skills!
๐ฏ Perfect for Students โข Freshers โข Job Seekers โข Working Professionals
โ Learn at your own pace โ Build career-relevant skills โ Explore available certificates and credentials
๐ ๐๐ฐ๐ฐ๐ฒ๐๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ฒ๐ฟ๐ฒ ๐
https://pdlink.in/3Uf5trR
๐ฅ Share with friends looking to upskill in 2026!
โค1
๐ฌ Kandinsky 6.0 Video: Training Details and Architecture
The new Kandinsky 6.0 Video lineup โ the flagship Pro (29B) and the lightweight Lite (3B) โ uses a dual-stream architecture: a video stream and an audio stream connected by bidirectional cross-attention.
๐ Training methodology:
โข Audio stream: pretrained from scratch on 40 million audio tracks; joint training: 7 million audio-video segments
โข Selection criteria: high-quality sound, close-up shots of speaking people
โข Objective: precise synchronization of speech and facial expressions
๐ Architecture:
Two connected streams:
1. Video stream
2. Audio stream
The streams are connected by bidirectional cross-attention for temporal and semantic alignment.
๐ฏ Key capabilities:
โข Lip-sync technology
โข Wide audio range (speech, effects, ambient)
โข Consumer GPU deployment (block offloading, 16โ32 GB VRAM presets)
โข Realistic physics modeling
๐ Performance metrics:
โข vs Kandinsky 5.0: clear advantage across all criteria (visual quality, prompt adherence, camera movement)
โข vs LTX 2.5: preferred in visual quality and speech quality
โข vs Veo 3.1 Fast: superior in image animation tasks
๐ง Specifications:
โข Resolutions: SD, HD, Full HD
โข Audio quality: 44 kHz
โข Duration: up to 5 seconds
โข License: MIT
๐ Hugging Face
The new Kandinsky 6.0 Video lineup โ the flagship Pro (29B) and the lightweight Lite (3B) โ uses a dual-stream architecture: a video stream and an audio stream connected by bidirectional cross-attention.
๐ Training methodology:
โข Audio stream: pretrained from scratch on 40 million audio tracks; joint training: 7 million audio-video segments
โข Selection criteria: high-quality sound, close-up shots of speaking people
โข Objective: precise synchronization of speech and facial expressions
๐ Architecture:
Two connected streams:
1. Video stream
2. Audio stream
The streams are connected by bidirectional cross-attention for temporal and semantic alignment.
๐ฏ Key capabilities:
โข Lip-sync technology
โข Wide audio range (speech, effects, ambient)
โข Consumer GPU deployment (block offloading, 16โ32 GB VRAM presets)
โข Realistic physics modeling
๐ Performance metrics:
โข vs Kandinsky 5.0: clear advantage across all criteria (visual quality, prompt adherence, camera movement)
โข vs LTX 2.5: preferred in visual quality and speech quality
โข vs Veo 3.1 Fast: superior in image animation tasks
๐ง Specifications:
โข Resolutions: SD, HD, Full HD
โข Audio quality: 44 kHz
โข Duration: up to 5 seconds
โข License: MIT
๐ Hugging Face
โค4
๐ฎ๐ณ ๐๐ข๐ฉ๐๐ฅ๐ก๐ ๐๐ก๐ง ๐ข๐ ๐๐ก๐๐๐ โ ๐๐๐๐ง๐ ๐๐ก๐ง๐๐ฅ๐ก๐ฆ๐๐๐ฃ๐ฆ ๐ฎ๐ฌ๐ฎ๐ฒ ๐
Students and freshers can explore internship opportunities through the AICTE Internship Portal across multiple domains:
๐ป AI, Data Science & Web Development
๐ Digital Marketing & Business Development
๐ฐ Finance & Accounting
โ๏ธ Content Writing & Graphic Design
โ๏ธ Mechanical, Civil & Electrical Engineering
๐ ๐๐ต๐ฒ๐ฐ๐ธ ๐ข๐ฝ๐ฝ๐ผ๐ฟ๐๐๐ป๐ถ๐๐ถ๐ฒ๐ & ๐๐ฝ๐ฝ๐น๐ ๐
https://pdlink.in/4y3vcBl
๐ข Share this opportunity with your friends and classmates!
Students and freshers can explore internship opportunities through the AICTE Internship Portal across multiple domains:
๐ป AI, Data Science & Web Development
๐ Digital Marketing & Business Development
๐ฐ Finance & Accounting
โ๏ธ Content Writing & Graphic Design
โ๏ธ Mechanical, Civil & Electrical Engineering
๐ ๐๐ต๐ฒ๐ฐ๐ธ ๐ข๐ฝ๐ฝ๐ผ๐ฟ๐๐๐ป๐ถ๐๐ถ๐ฒ๐ & ๐๐ฝ๐ฝ๐น๐ ๐
https://pdlink.in/4y3vcBl
๐ข Share this opportunity with your friends and classmates!
โค4
What is the main purpose of DISTINCT?
Anonymous Quiz
9%
A) Sort rows
60%
B) Remove duplicate rows from the result
20%
C) Delete duplicate rows from the table
11%
D) Group rows for calculations
๐ ๐ช๐ต๐ถ๐ฐ๐ต ๐ง๐ฒ๐ฐ๐ต ๐ฆ๐ธ๐ถ๐น๐น ๐ช๐ถ๐น๐น ๐ฌ๐ผ๐ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ถ๐ป ๐ฎ๐ฌ๐ฎ๐ฒ?
Want to build apps, uncover insights, or create AI solutions? Explore certification courses that match your career goals! ๐ฏ
๐ป ๐๐๐น๐น ๐ฆ๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐บ๐ฒ๐ป๐
๐ https://pdlink.in/3SuUeuD
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐
๐ https://pdlink.in/45vk5ph
๐ซ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ถ๐ป๐ด
๐ https://pdlink.in/4fWJVID
๐ฅ Choose your path, sharpen your skills, and take the next step towards your tech career!
๐ Save this post & share it with a friend planning to upskill.
Want to build apps, uncover insights, or create AI solutions? Explore certification courses that match your career goals! ๐ฏ
๐ป ๐๐๐น๐น ๐ฆ๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐บ๐ฒ๐ป๐
๐ https://pdlink.in/3SuUeuD
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐
๐ https://pdlink.in/45vk5ph
๐ซ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ถ๐ป๐ด
๐ https://pdlink.in/4fWJVID
๐ฅ Choose your path, sharpen your skills, and take the next step towards your tech career!
๐ Save this post & share it with a friend planning to upskill.
โค3
๐ Data Science Roadmap 2026
๐ Phase 3: SQL for Data Science
๐ Topic 6 โ GROUP BY
GROUP BY is used to group rows that have the same value in one or more columns.
It is mainly used when you want to perform calculations for each group.
For example:
โข Total sales by region
โข Average salary by department
โข Number of customers by city
โข Total orders by product
โข Maximum transaction by category
๐น Basic Syntax
Common aggregate functions:
โข
โข
โข
โข
โข
๐น Simple Example
Suppose we have:
Query:
Result:
Instead of calculating one overall average, SQL calculates an average for each department.
๐น GROUP BY with COUNT()
To count employees in each department:
Result:
๐น GROUP BY with SUM()
Suppose you have sales data:
Query:
Result:
This is extremely common in business analytics.
๐น GROUP BY with MAX()
Find the highest salary in each department:
๐น GROUP BY with MIN()
Find the lowest salary in each department:
๐น GROUP BY with Multiple Columns
You can group by multiple columns.
Here SQL creates groups based on:
For example:
๐น GROUP BY with WHERE
WHERE filters rows before grouping.
๐น GROUP BY with ORDER BY
You can sort grouped results.
For example, find departments with the highest total salary first:
This is very useful for ranking groups.
๐น GROUP BY vs DISTINCT
These two can sometimes look similar.
DISTINCT
Used to find unique departments.
GROUP BY
๐ Phase 3: SQL for Data Science
๐ Topic 6 โ GROUP BY
GROUP BY is used to group rows that have the same value in one or more columns.
It is mainly used when you want to perform calculations for each group.
For example:
โข Total sales by region
โข Average salary by department
โข Number of customers by city
โข Total orders by product
โข Maximum transaction by category
๐น Basic Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;
Common aggregate functions:
โข
COUNT() โ Count rowsโข
SUM() โ Calculate totalโข
AVG() โ Calculate averageโข
MIN() โ Find minimumโข
MAX() โ Find maximum๐น Simple Example
Suppose we have:
department salary
IT 60000
IT 80000
HR 50000
HR 70000
Finance 90000
Query:
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department;
Result:
department avg_salary
IT 70000
HR 60000
Finance 90000
Instead of calculating one overall average, SQL calculates an average for each department.
๐น GROUP BY with COUNT()
To count employees in each department:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;
Result:
department employee_count
IT 2
HR 2
Finance 1
๐น GROUP BY with SUM()
Suppose you have sales data:
region sales
North 10000
North 15000
South 20000
South 12000
Query:
SELECT region, SUM(sales) AS total_sales
FROM sales
GROUP BY region;
Result:
North 25000
South 32000
This is extremely common in business analytics.
๐น GROUP BY with MAX()
Find the highest salary in each department:
SELECT department, MAX(salary) AS highest_salary
FROM employees
GROUP BY department;
๐น GROUP BY with MIN()
Find the lowest salary in each department:
SELECT department, MIN(salary) AS lowest_salary
FROM employees
GROUP BY department;
๐น GROUP BY with Multiple Columns
You can group by multiple columns.
SELECT department, job_title, COUNT(*) AS employee_count
FROM employees
GROUP BY department, job_title;
Here SQL creates groups based on:
department + job_titleFor example:
IT Analyst 5
IT Developer 8
HR Analyst 3
Finance Manager 4
๐น GROUP BY with WHERE
WHERE filters rows before grouping.
SELECT department, AVG(salary) AS avg_salary
FROM employees
WHERE salary > 50000
GROUP BY department;
๐น GROUP BY with ORDER BY
You can sort grouped results.
For example, find departments with the highest total salary first:
SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department
ORDER BY total_salary DESC;
This is very useful for ranking groups.
๐น GROUP BY vs DISTINCT
These two can sometimes look similar.
DISTINCT
SELECT DISTINCT department
FROM employees;
Used to find unique departments.
GROUP BY
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
โค3
Used when you want to perform calculations for each department.
Simple rule:
DISTINCT โ Give me unique values
GROUP BY โ Give me groups so I can calculate something
๐น Real-World Data Science Example
Imagine an e-commerce dataset.
You want to know the total revenue generated by each product category.
This gives you a category-level summary that can be used for:
โข Revenue analysis
โข Product performance
โข Business reporting
โข Feature creation
โข Exploratory data analysis
๐น Common Mistake
Consider:
This can cause an error in many SQL databases because employee_name is neither:
โข included in GROUP BY, nor
โข used inside an aggregate function.
A valid query would be:
๐น Important Rule
When using GROUP BY, selected columns generally need to be either:
1. Included in the GROUP BY, or
2. Wrapped inside an aggregate function.
Example:
๐น Interview Questions
1. What is GROUP BY?
GROUP BY groups rows with the same values so aggregate calculations can be performed for each group.
2. Which aggregate functions are commonly used with GROUP BY?
3. What is the difference between WHERE and GROUP BY?
WHERE filters individual rows before grouping.
GROUP BY creates groups from the filtered rows.
4. Can GROUP BY use multiple columns?
Yes.
5. Can GROUP BY be used without aggregate functions?
Yes, although DISTINCT is often clearer when the goal is simply to return unique combinations.
๐ฏ Practice Questions
1. Find the number of employees in each department.
2. Find the average salary for each department.
3. Find the total sales for each region.
4. Find the highest salary in each department.
5. Find the total revenue for each product category and sort categories from highest to lowest revenue.
๐ฏ Key Takeaways
โข GROUP BY creates groups of similar rows.
โข It is commonly used with aggregate functions.
โข
โข
โข
โข
โข
โข WHERE filters rows before grouping.
โข ORDER BY can sort grouped results.
โข GROUP BY is one of the most important SQL concepts for Data Science and Analytics.
๐Double Tap โค๏ธ For More
Simple rule:
DISTINCT โ Give me unique values
GROUP BY โ Give me groups so I can calculate something
๐น Real-World Data Science Example
Imagine an e-commerce dataset.
You want to know the total revenue generated by each product category.
SELECT category,
SUM(quantity * price) AS total_revenue
FROM sales
GROUP BY category
ORDER BY total_revenue DESC;
This gives you a category-level summary that can be used for:
โข Revenue analysis
โข Product performance
โข Business reporting
โข Feature creation
โข Exploratory data analysis
๐น Common Mistake
Consider:
SELECT department, employee_name, AVG(salary)
FROM employees
GROUP BY department;
This can cause an error in many SQL databases because employee_name is neither:
โข included in GROUP BY, nor
โข used inside an aggregate function.
A valid query would be:
SELECT department, AVG(salary)
FROM employees
GROUP BY department;
๐น Important Rule
When using GROUP BY, selected columns generally need to be either:
1. Included in the GROUP BY, or
2. Wrapped inside an aggregate function.
Example:
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
department โ grouped columnCOUNT(*) โ aggregate ๐น Interview Questions
1. What is GROUP BY?
GROUP BY groups rows with the same values so aggregate calculations can be performed for each group.
2. Which aggregate functions are commonly used with GROUP BY?
COUNT(), SUM(), AVG(), MIN(), and MAX().3. What is the difference between WHERE and GROUP BY?
WHERE filters individual rows before grouping.
GROUP BY creates groups from the filtered rows.
4. Can GROUP BY use multiple columns?
Yes.
GROUP BY department, job_title;5. Can GROUP BY be used without aggregate functions?
Yes, although DISTINCT is often clearer when the goal is simply to return unique combinations.
๐ฏ Practice Questions
1. Find the number of employees in each department.
2. Find the average salary for each department.
3. Find the total sales for each region.
4. Find the highest salary in each department.
5. Find the total revenue for each product category and sort categories from highest to lowest revenue.
๐ฏ Key Takeaways
โข GROUP BY creates groups of similar rows.
โข It is commonly used with aggregate functions.
โข
COUNT() counts.โข
SUM() totals.โข
AVG() calculates averages.โข
MIN() finds the minimum.โข
MAX() finds the maximum.โข WHERE filters rows before grouping.
โข ORDER BY can sort grouped results.
โข GROUP BY is one of the most important SQL concepts for Data Science and Analytics.
๐Double Tap โค๏ธ For More
โค5
๐ง๐ข๐ฃ ๐๐ฅ๐๐ ๐๐ข๐จ๐ฅ๐ฆ๐๐ฆ ๐ง๐ข ๐๐ข๐ข๐ฆ๐ง ๐ฌ๐ข๐จ๐ฅ ๐ฆ๐๐๐๐๐ฆ ๐๐ก ๐ฎ๐ฌ๐ฎ๐ฒ!
Explore FREE online learning resources to develop in-demand skills and improve your career opportunities!
๐ Why Explore These Courses?
โ Learn valuable professional skills
โ Improve your resume
โ Build practical knowledge
โ Learn at your own pace
๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ฒ๐ฟ๐ฒ๐
https://pdlink.in/3VBdt6V
๐ก Learn New Skills โ Build Confidence โ Unlock Career Opportunities!
Explore FREE online learning resources to develop in-demand skills and improve your career opportunities!
๐ Why Explore These Courses?
โ Learn valuable professional skills
โ Improve your resume
โ Build practical knowledge
โ Learn at your own pace
๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ฒ๐ฟ๐ฒ๐
https://pdlink.in/3VBdt6V
๐ก Learn New Skills โ Build Confidence โ Unlock Career Opportunities!
โค1
Which aggregate function calculates the average salary?
Anonymous Quiz
5%
A) SUM()
4%
B) COUNT()
88%
C) AVG()
3%
D) TOTAL()
โค2
Which clause filters rows before GROUP BY?
Anonymous Quiz
22%
A) HAVING
34%
B) ORDER BY
42%
C) WHERE
2%
D) LIMIT
โค1
What is the main difference between DISTINCT and GROUP BY?
Anonymous Quiz
12%
A) DISTINCT sorts data while GROUP BY filters data
84%
B) DISTINCT removes duplicate results, while GROUP BY is commonly used for grouping and aggregation
4%
C) GROUP BY deletes duplicate rows
1%
D) There is no difference
โค4๐1๐ข1
What does this query return?
SELECT department, SUM(salary) AS total_salary
FROM employees GROUP BY department;
SELECT department, SUM(salary) AS total_salary
FROM employees GROUP BY department;
Anonymous Quiz
13%
A) The highest salary in each department
12%
B) The average salary in each department
70%
C) The total salary for each department
5%
D) The number of employees in each department
โค2
๐๐ฎ๐๐ฎ ๐๐ฐ๐ถ๐ฒ๐ป๐ฐ๐ฒ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐ช๐ถ๐๐ต ๐๐๐
Future Ready Data Science and AI Skills You Build
->Build Python, Machine Learning, and AI Skills
->Get Mentored by Industry Experts
->Practice with Mock Interviews
->Ace Your Placements & Land Dream Tech Job
๐ค 500+ Partner Companies |๐ 2000+ Students Placed
๐ ๐ฅ๐ฒ๐ด๐ถ๐๐๐ฒ๐ฟ ๐ก๐ผ๐ ๐ :-
https://pdlink.in/47pezFz
๐ฒ Save & Share with Friends Preparing for Data Science & AI Jobs!
Future Ready Data Science and AI Skills You Build
->Build Python, Machine Learning, and AI Skills
->Get Mentored by Industry Experts
->Practice with Mock Interviews
->Ace Your Placements & Land Dream Tech Job
๐ค 500+ Partner Companies |๐ 2000+ Students Placed
๐ ๐ฅ๐ฒ๐ด๐ถ๐๐๐ฒ๐ฟ ๐ก๐ผ๐ ๐ :-
https://pdlink.in/47pezFz
๐ฒ Save & Share with Friends Preparing for Data Science & AI Jobs!
โค3
๐๐๐ ๐๐ฅ๐๐ ๐ง๐๐๐ ๐๐ข๐จ๐ฅ๐ฆ๐๐ฆ ๐ฎ๐ฌ๐ฎ๐ฒ! ๐
Explore IBM Cognitive Class and build in-demand tech skills without spending money on course fees!
๐ ๐ง๐ผ๐ฝ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ผ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ:-
๐ซ Artificial Intelligence & Machine Learning
๐ฅPython for Data Science
๐ Data Science Fundamentals
โ๏ธ Cloud Computing & Big Data
๐ ๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐๐ฒ๐ฟ๐ฒ ๐
https://pdlink.in/4zGswuX
๐ฒ Save & Share with friends preparing for tech careers! ๐ฅ
Explore IBM Cognitive Class and build in-demand tech skills without spending money on course fees!
๐ ๐ง๐ผ๐ฝ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ผ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ:-
๐ซ Artificial Intelligence & Machine Learning
๐ฅPython for Data Science
๐ Data Science Fundamentals
โ๏ธ Cloud Computing & Big Data
๐ ๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐๐ฒ๐ฟ๐ฒ ๐
https://pdlink.in/4zGswuX
๐ฒ Save & Share with friends preparing for tech careers! ๐ฅ
โค2
๐ Data Science Roadmap 2026
๐ Phase 3: SQL for Data Science
๐ Topic 7 โ HAVING
HAVING is used to filter grouped results.
The most important thing to remember:
WHERE โ filters rows
HAVING โ filters groups
๐น Why Do We Need HAVING?
Suppose you want to find departments that have more than 5 employees.
First, you need to group employees by department:
But if you want only departments with more than 5 employees, use HAVING:
The grouping happens first, and then HAVING filters the groups.
๐น Basic Syntax
๐น HAVING with COUNT()
Find departments having more than 10 employees:
๐น HAVING with SUM()
Find regions where total sales exceed 100000:
๐น HAVING with AVG()
Find departments where the average salary is greater than 70000:
๐น HAVING with MAX()
Find departments where the highest salary is greater than 150000:
๐น WHERE vs HAVING
This is one of the most frequently asked SQL interview questions.
WHERE Filters individual rows.
It removes individual records that don't meet the condition.
HAVING
Filters groups after GROUP BY.
It removes entire groups that don't meet the condition.
๐น Using WHERE and HAVING Together
You can use both.
Suppose you want departments where:
โข Only employees earning more than 50000 are considered
โข The department must have at least 5 such employees
Conceptually:
๐น HAVING with ORDER BY
You can also sort the filtered groups.
This finds departments whose total salary exceeds 500000 and displays the highest totals first.
๐น HAVING Without GROUP BY
Some SQL databases allow HAVING without an explicit GROUP BY, treating the entire result as a single group.
For example:
This returns the result only if there are more than 100 employees.
For beginners, however, focus primarily on the common pattern:
GROUP BY โ HAVING
๐น Common Mistake
โ Incorrect:
๐ Phase 3: SQL for Data Science
๐ Topic 7 โ HAVING
HAVING is used to filter grouped results.
The most important thing to remember:
WHERE โ filters rows
HAVING โ filters groups
๐น Why Do We Need HAVING?
Suppose you want to find departments that have more than 5 employees.
First, you need to group employees by department:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;
But if you want only departments with more than 5 employees, use HAVING:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;
The grouping happens first, and then HAVING filters the groups.
๐น Basic Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name
HAVING condition;
๐น HAVING with COUNT()
Find departments having more than 10 employees:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 10;
๐น HAVING with SUM()
Find regions where total sales exceed 100000:
SELECT region, SUM(sales) AS total_sales
FROM sales
GROUP BY region
HAVING SUM(sales) > 100000;
๐น HAVING with AVG()
Find departments where the average salary is greater than 70000:
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 70000;
๐น HAVING with MAX()
Find departments where the highest salary is greater than 150000:
SELECT department, MAX(salary) AS highest_salary
FROM employees
GROUP BY department
HAVING MAX(salary) > 150000;
๐น WHERE vs HAVING
This is one of the most frequently asked SQL interview questions.
WHERE Filters individual rows.
SELECT *
FROM employees
WHERE salary > 50000;
It removes individual records that don't meet the condition.
HAVING
Filters groups after GROUP BY.
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 70000;
It removes entire groups that don't meet the condition.
๐น Using WHERE and HAVING Together
You can use both.
Suppose you want departments where:
โข Only employees earning more than 50000 are considered
โข The department must have at least 5 such employees
SELECT department, COUNT(*) AS employee_count
FROM employees
WHERE salary > 50000
GROUP BY department
HAVING COUNT(*) >= 5;
Conceptually:
All employees
โ
WHERE
โ
Employees with salary > 50000
โ
GROUP BY
โ
Create department groups
โ
HAVING
โ
Keep groups with at least 5 employees
๐น HAVING with ORDER BY
You can also sort the filtered groups.
SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department
HAVING SUM(salary) > 500000
ORDER BY total_salary DESC;
This finds departments whose total salary exceeds 500000 and displays the highest totals first.
๐น HAVING Without GROUP BY
Some SQL databases allow HAVING without an explicit GROUP BY, treating the entire result as a single group.
For example:
SELECT COUNT(*) AS employee_count
FROM employees
HAVING COUNT(*) > 100;
This returns the result only if there are more than 100 employees.
For beginners, however, focus primarily on the common pattern:
GROUP BY โ HAVING
๐น Common Mistake
โ Incorrect:
SELECT department, COUNT(*)
FROM employees
WHERE COUNT(*) > 5
GROUP BY department;
โค1
Aggregate functions such as COUNT() generally cannot be used in WHERE.
โ Correct:
๐น Real-World Data Science Example
Suppose you're analyzing customer transactions.
You want customers who have made at least 10 transactions:
This can help identify:
โข Frequent customers
โข High-engagement users
โข Active accounts
โข Customers suitable for segmentation
Another example:
Find products generating more than 50000 in revenue:
๐น Interview Questions
What is HAVING?
HAVING filters groups created by GROUP BY.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping.
HAVING filters groups after grouping.
Can HAVING be used with aggregate functions?
Yes.
Can WHERE and HAVING be used together?
Yes.
Why can't we normally use COUNT() in WHERE?
Because WHERE operates on individual rows before the aggregation is performed. HAVING is designed to filter aggregated groups.
๐ฏ Practice Questions
1. Find departments with more than 10 employees.
2. Find customers who have made at least 5 transactions.
3. Find regions where total sales exceed 100000.
4. Find departments where average salary is greater than 75000.
5. Find products whose total revenue exceeds 50000 and sort them from highest to lowest revenue.
๐ฏ Key Takeaways
โข WHERE โ Filters rows.
โข GROUP BY โ Creates groups.
โข HAVING โ Filters groups.
โข WHERE is applied before grouping.
โข HAVING is applied after grouping.
โข HAVING is commonly used with COUNT(), SUM(), AVG(), MIN(), and MAX().
โข WHERE + GROUP BY + HAVING is one of the most important SQL patterns for analytics.
๐ Double Tap โค๏ธ For More
โ Correct:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;
๐น Real-World Data Science Example
Suppose you're analyzing customer transactions.
You want customers who have made at least 10 transactions:
SELECT customer_id,
COUNT(*) AS transaction_count
FROM transactions
GROUP BY customer_id
HAVING COUNT(*) >= 10;
This can help identify:
โข Frequent customers
โข High-engagement users
โข Active accounts
โข Customers suitable for segmentation
Another example:
Find products generating more than 50000 in revenue:
SELECT product_id,
SUM(quantity * price) AS revenue
FROM sales
GROUP BY product_id
HAVING SUM(quantity * price) > 50000
ORDER BY revenue DESC;
๐น Interview Questions
What is HAVING?
HAVING filters groups created by GROUP BY.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping.
HAVING filters groups after grouping.
Can HAVING be used with aggregate functions?
Yes.
HAVING COUNT(*) > 5Can WHERE and HAVING be used together?
Yes.
WHERE salary > 50000
GROUP BY department
HAVING COUNT(*) > 5
Why can't we normally use COUNT() in WHERE?
Because WHERE operates on individual rows before the aggregation is performed. HAVING is designed to filter aggregated groups.
๐ฏ Practice Questions
1. Find departments with more than 10 employees.
2. Find customers who have made at least 5 transactions.
3. Find regions where total sales exceed 100000.
4. Find departments where average salary is greater than 75000.
5. Find products whose total revenue exceeds 50000 and sort them from highest to lowest revenue.
๐ฏ Key Takeaways
โข WHERE โ Filters rows.
โข GROUP BY โ Creates groups.
โข HAVING โ Filters groups.
โข WHERE is applied before grouping.
โข HAVING is applied after grouping.
โข HAVING is commonly used with COUNT(), SUM(), AVG(), MIN(), and MAX().
โข WHERE + GROUP BY + HAVING is one of the most important SQL patterns for analytics.
๐ Double Tap โค๏ธ For More
โค7