Experiment 09
Aim
To demonstrate the use of aggregate functions i.e., like, wildcards, in, and between
Theory
Aggregate functions perform a calculation on a set of values and return a single value. They are often used with the GROUP BY clause in SQL to group the result set by one or more columns.
-
Like:
The
LIKEoperator is used in aWHEREclause to search for a specified pattern in a column.SyntaxSELECT column_name(s) FROM table_name WHERE column_name LIKE pattern; -
Wildcards:
The
%wildcard represents zero or more characters, while the_wildcard represents a single character.SyntaxSELECT column_name(s) FROM table_name WHERE column_name LIKE 'a%'; -- Finds any values that start with "a"
SELECT column_name(s) FROM table_name WHERE column_name LIKE '_a%'; -- Finds any values that have "a" in the second position -
In:
The
INoperator allows you to specify multiple values in aWHEREclause.SyntaxSELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...); -
Between:
The
BETWEENoperator selects values within a given range. The values can be numbers, text, or dates.SyntaxSELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
Commands
SELECT * FROM Employees WHERE name LIKE 'J%';
SELECT * FROM Employees WHERE name LIKE '_a%';
SELECT * FROM Employees WHERE department IN ('HR', 'Finance');
SELECT * FROM Employees WHERE salary BETWEEN 50000 AND 100000;
Conclusion
Successfully demonstrated the use of various aggregate functions in SQL, including
LIKE, wildcards,IN, andBETWEEN