Skip to main content

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 LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

    Syntax
    SELECT 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.

    Syntax
    SELECT 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 IN operator allows you to specify multiple values in a WHERE clause.

    Syntax
    SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);
  • Between:

    The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.

    Syntax
    SELECT 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, and BETWEEN