Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

Some SQL Functions

The document describes 18 functions used for data analysis, including aggregate functions like COUNT, SUM, AVG, MIN, and MAX, string functions such as CONCAT, UPPER, LOWER, and LENGTH, and date functions like GETDATE, DATEPART, DATEADD, DATEDIFF, and YEAR. These functions are used to perform calculations on data in columns, manipulate strings, extract parts of dates, and calculate differences between dates. Syntax examples are provided for each function.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Some SQL Functions

The document describes 18 functions used for data analysis, including aggregate functions like COUNT, SUM, AVG, MIN, and MAX, string functions such as CONCAT, UPPER, LOWER, and LENGTH, and date functions like GETDATE, DATEPART, DATEADD, DATEDIFF, and YEAR. These functions are used to perform calculations on data in columns, manipulate strings, extract parts of dates, and calculate differences between dates. Syntax examples are provided for each function.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

D 01

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:

This function returns the maximum value in a column.


Syntax:
·----------------------------------------------,
I I
SELECT MAX(column_ name) FROM tab/e_ name:
~----------------------------------------------J

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:

SELECT co/umn_name, COUNT(column_name},


SUM(column_name}, AVG(column_name},
MIN(co/umn_name}, MAX(column_name)
FROM tab/e_name CROUP BY column_name;
OS

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:

This function is used to convert all characters In a string


to lowercase.

,----------------------------------------· 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:

This function is used to remove leading or trailing spaces


from a string.
Syntax:
,--------------- ---- -------------------1 I
SELECT TRIM(string) FROM table_name; 1
I I
·--------------------------------------·

12. SUBSTAINC O:
This function is used to extract a substring from a larger
string.
Syntax:
·----------------------------------------------·
I I

SELECT SUBSTRING(string, start_ position, length )


FROM table_name;
·----------------------------------------------·
D 08

••• • •
13. REPLACE O: •• • • •
This function is used to replace a substring within a string • •
with a different substring.
Syntax:

SELECT REPLACE(string, o/d_substring, new_substring)


FROM tab/e_name;

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

' SELECT DATEDIFF(unit, start_date. end_date) FROM tab/e_name; '

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
~----------------------------------·

You might also like