filmov
tv
Group By Clause in MySQL|| MySQL Tutorial || Code With Neha
Показать описание
On my previous video of mysql series
I have discussed about count,avg and sum aggregate functions in mysql
You can check the video from the above I button
Today's we will be discussing about group by clause in mysql
The MySQL GROUP BY Statement
The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.
GROUP BY Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
GROUP BY Syntax using ORDER BY Clause
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
Let us see with examples
Today I will be using CUSTOMERS_DETAILS table under order_info database
1st example
Query to group the table with ID and age
SELECT ID,AGE
FROM CUSTOMERS_DETAILS
GROUP BY AGE;
Example 2:-
Query to group customers based on their age
SELECT COUNT(ID),AGE
FROM CUSTOMERS_DETAILS
GROUP BY AGE;
HERE WE NEED TO CATEGORIES CUSTOMERS WITH SIMILAR AGE GROUP
SO WE ARE COUNTING THE NO OF CUSTOMERS WITH SIMILAR AGE
Example 3:-
QUERY TO GROUP CUSTOMERS BY THEIR AGE AND CALCULATE AVERAGE SALARY FOR EACH AGE
SELECT COUNT(ID),AGE,AVG(SALARY) AS average_salary
FROM CUSTOMERS_DETAILS
GROUP BY AGE
Example 4:-
QUERY TO GROUP CUSTOMERS BY THEIR AGE AND CALCULATE TOTAL SALARY FOR EACH AGE
SELECT COUNT(ID),SUM(SALARY),AGE
FROM CUSTOMERS_DETAILS
GROUP BY AGE
Example 5:-
QUERY TO GROUP CUSTOMERS BY THEIR AGE AND CALCULATE SALARY FOR EACH AGE WITH CONCATINATION
SELECT CONCAT(AGE,'--',SALARY) AS salary_agewise
FROM CUSTOMERS_DETAILS
GROUP BY AGE,SALARY;
Example 6:-
QUERY TO FIND THE MAXIMUM SALARY FOR EACH AGE
SELECT AGE,MAX(SALARY)AS max_salary
FROM CUSTOMERS_DETAILS
GROUP BY AGE
ORDER BY SUM(SALARY)DESC;
And that's all for today Hope you all will get some help from this video
If it's so then don't forget to subscribe my channel Code with Neha and press the Bell Icon for Regular Updates
See you in the next video till then Stay Safe Stay Happy
#groupbyclause
#groupbyclauseinsql
#groupbyclauseinmysql
#mysqlgroupbyclause
#useofgroupbyclauseinmysql
#clausesinsql
#whatisgroupbyinsqlquery?
#groupbyinsqlwithwherecondition
#examplesofgroupbyclause
#examplesofgroupbyclauseinmysql
#sqltutorialsforbeginners
#sqlgroupbytutorial
#sqlgroupbyexamples
#groupbyinsql
#groupbyinmysql
#mysqlgroupby
#groupbystatementinmysql
#learnmysql
#mysqltutorial
#mysqldatabase
#mysqlcourse
#mysqldatabasetutorial
#mysqlcrashcourse
#mysqltutorialforbeginners
#sqlforbeginners
#groupbyclausesyntax
#sqlgroupby
#sqltutorial
#sqltutorialforbeginners
#mysqltutorial
#mysqltutorialforbeginners
#mysql
#mysqldatabase
#coding
I have discussed about count,avg and sum aggregate functions in mysql
You can check the video from the above I button
Today's we will be discussing about group by clause in mysql
The MySQL GROUP BY Statement
The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.
GROUP BY Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
GROUP BY Syntax using ORDER BY Clause
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
Let us see with examples
Today I will be using CUSTOMERS_DETAILS table under order_info database
1st example
Query to group the table with ID and age
SELECT ID,AGE
FROM CUSTOMERS_DETAILS
GROUP BY AGE;
Example 2:-
Query to group customers based on their age
SELECT COUNT(ID),AGE
FROM CUSTOMERS_DETAILS
GROUP BY AGE;
HERE WE NEED TO CATEGORIES CUSTOMERS WITH SIMILAR AGE GROUP
SO WE ARE COUNTING THE NO OF CUSTOMERS WITH SIMILAR AGE
Example 3:-
QUERY TO GROUP CUSTOMERS BY THEIR AGE AND CALCULATE AVERAGE SALARY FOR EACH AGE
SELECT COUNT(ID),AGE,AVG(SALARY) AS average_salary
FROM CUSTOMERS_DETAILS
GROUP BY AGE
Example 4:-
QUERY TO GROUP CUSTOMERS BY THEIR AGE AND CALCULATE TOTAL SALARY FOR EACH AGE
SELECT COUNT(ID),SUM(SALARY),AGE
FROM CUSTOMERS_DETAILS
GROUP BY AGE
Example 5:-
QUERY TO GROUP CUSTOMERS BY THEIR AGE AND CALCULATE SALARY FOR EACH AGE WITH CONCATINATION
SELECT CONCAT(AGE,'--',SALARY) AS salary_agewise
FROM CUSTOMERS_DETAILS
GROUP BY AGE,SALARY;
Example 6:-
QUERY TO FIND THE MAXIMUM SALARY FOR EACH AGE
SELECT AGE,MAX(SALARY)AS max_salary
FROM CUSTOMERS_DETAILS
GROUP BY AGE
ORDER BY SUM(SALARY)DESC;
And that's all for today Hope you all will get some help from this video
If it's so then don't forget to subscribe my channel Code with Neha and press the Bell Icon for Regular Updates
See you in the next video till then Stay Safe Stay Happy
#groupbyclause
#groupbyclauseinsql
#groupbyclauseinmysql
#mysqlgroupbyclause
#useofgroupbyclauseinmysql
#clausesinsql
#whatisgroupbyinsqlquery?
#groupbyinsqlwithwherecondition
#examplesofgroupbyclause
#examplesofgroupbyclauseinmysql
#sqltutorialsforbeginners
#sqlgroupbytutorial
#sqlgroupbyexamples
#groupbyinsql
#groupbyinmysql
#mysqlgroupby
#groupbystatementinmysql
#learnmysql
#mysqltutorial
#mysqldatabase
#mysqlcourse
#mysqldatabasetutorial
#mysqlcrashcourse
#mysqltutorialforbeginners
#sqlforbeginners
#groupbyclausesyntax
#sqlgroupby
#sqltutorial
#sqltutorialforbeginners
#mysqltutorial
#mysqltutorialforbeginners
#mysql
#mysqldatabase
#coding