Some SQL Functions
Some SQL Functions
L
Functions
used for Data Analysis task
Startt)
• • • • •
•02• • •
II •
Aggregate functions
1. COUNT0:
This function returns the number of rows in a table or
the number of non-null values in a column.
Syntax:
·----------------------------------------------·
I I
SELECT COUNT(column_ name) FROM tab/e_ name;
·----------------------------------------------'
2. SUM 0:
This function returns the sum of all values in a numeric
column.
Syntax:
·----------------------------------------------·
I I
SELECT SUM(co/umn_ name) FROM table_ name;
·----------------------------------------------·
a 03
3. AVCO:
Th is function returns the average of all values in a
numeric column.
Syntax:
·----------------------------------------------·
I
SELECT AVG(column_ name) FROM table_ name;
·------------------------------------------ ----·
4. MINO:
This function returns the minimum value in a column.
Syntax:
·----------------------------------------------· I
SELECT MIN(column_ name) FROM tab/e_name;
·----------------------------------------------·
• • • • • •
• • • • • •
• • • • • •
• ••• •
D 04
5. MAXO:
6. CROUP BY O:
This function is used to group the rows In a table
based on the values In one or more columns, and
then perform aggregate functions on each group.
Syntax:
String Functions • • • • •
•••••
• • • • •
7. CONCAT0:
This function is used to concatenate two or more
strings together.
Syntax:
·----------------------------------------------· I
SELECT CONCAT(string7, string2) FROM table_ name;
·----------------------------------------------·
8. UPPER O:
This function is used to convert all characters in a string
to uppercase.
Syntax:
·--------------------------------------·
I
1 SELECT UPPER(string) FROM table_name;
I
·--------------------------------------·
D 06
9. LOWER 0:
,----------------------------------------· I
SELECT LOWER(string) FROM tab/e_name; 1
I
·----------------------------------------·
10. LENCTH O:
This function is used to return the length of a string.
Syntax:
,----------------------------------------------·
SELECT LENGTH(string) FROM tab/e_name;
·----------------------------------------------·
a 07
11. TRIM O:
12. SUBSTAINC O:
This function is used to extract a substring from a larger
string.
Syntax:
·----------------------------------------------·
I I
••• • •
13. REPLACE O: •• • • •
This function is used to replace a substring within a string • •
with a different substring.
Syntax:
Date Functions
14. CETDATE O:
This function returns the current date and time.
·- ----------------------------------·
I
SELECT GETDATE() FROM tab/e_name;
I
·-----------------------------------·
D 09
• • • • •
15. DATEPART O: •••••
This function is used to extract a specific part of a date, • • •
such as the year, month, or day.
Syntax:
·-------------------------------------------· I
I
SELECT DATEPART(part, date) FROM tab/e_name; I
I
16. DATEADD O:
This function is used to add a specified number of units
to a date or time value.
Syntax:
·----------------------------------------------·
I I
, SELECT DATEADD(unit, value, date) FROM tab/e_name; ,
I I
·----------------------------------------------·
10
• • • • •
17. DATEDIFF O: •• •••
Th is function is used to calculate the difference between • •
two dates or time values.
Syntax:
r------------------------------------------------------~
I I
18. YEAR O:
Th is fu net ion is used to extract the year from a date value.
Syntax:
·----------------------------------~
I I
, SELECT YEAR(date) FROM table_name;
I I
~----------------------------------·