Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

MySQL Introduction

MySQL Setup

MySQL Operators

MySQL Basic Works

MySQL Create Table

MySQL insert and get values

MySQL Condition

MySQL GROUP BY

MySQL Case

MySQL sorting and calculate avg,sum,count

MySQL Update

MySQL Time

MySQL String

MySQL Rollback & Commit

MySQL Join and Concatenate

MySQL Index

MySQL Date

MySQL View

MYSQL With Python

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

everything about sql group-by

GROUP BY create groups of those rows which contain the same values. This GROUP BY statement is used with aggregate functions like (MAX(), COUNT(), AVG(), SUM(), MIN() ) to group the result-set by one or more columns. We can also use condition to create groups.

Example: find the number of sells man in each country?
Here we will create a group of sells man according to the county. Because we want to get the number of sells man, so in aggregate functions, we can use sum.
Suppose we have total 12 rows and in the country column, we have total 3 different counties. So Here we will get total three groups and the groups values will be the sum of the total sells man contained by each country.
This way GROUP BY works.

Syntax:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)

We can also use oder by. It is used to sort the result:
Syntax:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

Example 1:
SELECT MAX(Books),Price
FROM first_table
WHERE Price>250
GROUP BY Books,Price;

Example 2:
SELECT Books,Price
FROM first_table
WHERE Price>250
GROUP BY Books,Price
ORDER BY Price desc;

Example 3:
SELECT Books,Price
FROM first_table
WHERE Price>250
GROUP BY Books,Price
ORDER BY COUNT(Price) desc;

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.