0% found this document useful (0 votes)
5 views3 pages

6 Exp

The document outlines various SQL aggregate functions including COUNT, SUM, AVG, MAX, and MIN, along with their usage examples. It also describes string operations such as UPPER, LOWER, LENGTH, CONCAT, SUBSTRING, TRIM, and REPLACE, providing SQL query examples for each. Additionally, it includes the LIKE operator for pattern matching in queries.

Uploaded by

gaurav.nullbyte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

6 Exp

The document outlines various SQL aggregate functions including COUNT, SUM, AVG, MAX, and MIN, along with their usage examples. It also describes string operations such as UPPER, LOWER, LENGTH, CONCAT, SUBSTRING, TRIM, and REPLACE, providing SQL query examples for each. Additionally, it includes the LIKE operator for pattern matching in queries.

Uploaded by

gaurav.nullbyte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exp6

Agregate function
1. COUNT()
SELECT COUNT(*) FROM table_name;
-- or
SELECT COUNT(column_name) FROM table_name;
SELECT COUNT(*) FROM employee;
or
SELECT COUNT(email) FROM employee;

2. SUM()

SELECT SUM(column_name) FROM table_name;

SELECT SUM(salary) FROM employee;

3. AVG()

SELECT AVG(column_name) FROM table_name;

SELECT AVG(salary) FROM employee;

4. MAX()

SELECT MAX(column_name) FROM table_name;

SELECT MAX(salary) FROM employee;

5. MIN()

SELECT MIN(column_name) FROM table_name;

SELECT MIN(salary) FROM employee;

6. GROUP BY (used with aggregate functions)

SELECT column_name, AGGREGATE_FUNCTION(column_name)

FROM table_name

GROUP BY column_name;

SELECT deptid, AVG(salary) FROM employee GROUP BY deptid;


String Operations
1. UPPER()
SELECT UPPER(column_name) FROM table_name;
SELECT UPPER(name) FROM employee;

2. LOWER()
SELECT LOWER(column_name) FROM table_name;
SELECT LOWER(name) FROM employee;

3. LENGTH()
SELECT LENGTH(column_name) FROM table_name;
SELECT LENGTH(email) FROM employee;

4. CONCAT()
SELECT CONCAT(string1, string2, ...) FROM table_name;
SELECT CONCAT(name, ' - ', email) FROM employee;

5. SUBSTRING() / SUBSTR()
SELECT SUBSTRING(column_name, start_position, length) FROM table_name;
SELECT SUBSTRING(email, 1, 5) FROM employee;

6. SUBSTRING_INDEX()
SELECT SUBSTRING_INDEX(column_name, 'delimiter', count) FROM table_name;
SELECT SUBSTRING_INDEX(email, '@', -1) FROM employee; -- Gets domain

7. TRIM()
SELECT TRIM(column_name) FROM table_name;
SELECT TRIM(' Gaurav ');
8. REPLACE()
SELECT REPLACE(column_name, 'search', 'replace') FROM table_name;
SELECT REPLACE(email, '.com', '.org') FROM employee;

9. LIKE
SELECT * FROM table_name WHERE column_name LIKE 'pattern';
SELECT * FROM employee WHERE name LIKE 'S%';

You might also like