Explain group by, order by clause of SQL with example.

Group by: 
The GROUP BY STATEMENT is used with aggregate functions (MAX, MIN, SUM,
COUNT etc.) to group the result-set by one or more columns;
Syntax:
Select Column-Name(s) from Table-Name where condition GROUP BY Column-Name;
Example:
Select COUNT (Roll_no), Branch from Student GROUP BY Branch;
Order By:
To achieve a specific order then one can use the ORDER BY clause. ORDER BY clause allows sorting by one or more columns. Records can be displayed in ascending or descending order.
Syntax:
SELECT Column-Name(s) from Table-name where condition ORDER BY Columnname(s) asc/desc;

Example:

SELECT 

ROLL_NO,
PERCENTAGE

FROM

STUDENT
ORDER
BY
PERCENTAGE;

Post a Comment

0 Comments