Some of the advanced Queries in SQL are as Follows:
1. SQL ORDER BY Clause:
Function: This query is used to sort the fetched records in either ascending or
descending order.
Syntax:
Select column1.column2 from tablename Order By Columname ASC|DESC
Let us understand with the help of an Example :
Table1: Customers
customerId customername customercontact country
1 Alferd Maria Germany
2 Ana
Ana Mexico
4 Antonio Antonio Mexico
Query1: SELECT customername,contactname from customers ORDER BY customername
Output:
customername | contactname | ||||||||
---|---|---|---|---|---|---|---|---|---|
Alferd | Maria | ||||||||
Ana | Ana | ||||||||
Antonio | Antonio |
Query2:
SELECT customername,contactname from customers ORDER BY customername DESC
Output:
2. SQL MIN() and MAX() Functions:
Syntax: Select MIN(columnname) from tablename where condition.
Function: This query is used to fetch out the minimum value from the column name
Syntax: Select MAX(columnname) from tablename where condition.
Function: This query is used to fetch out the maximum value from the column name
3.SQL COUNT() Function:
Syntax : Select count(columnname) from tablename where condition;
Function: This function is used to return the number of values in a particular column.
4. SQL AVG() Function:
Syntax: Select Avg(columnname) from tablename where condition;
Function: This function is used to return the average of the particular column.
5. SQL SUM() Function:
Syntax: Select Sum(columnname) from tablename where condition;
Function: This function is used to return the sum of a particular column.
No comments:
Post a Comment