2.aggregate GroupBy Logical
2.aggregate GroupBy Logical
AIM
To study basic SQL Aggregate and GROUP BY commands.
PROCEDURE
1. LOGICAL OPERATORS
OR: The OR Operator in SQL displays the records where any one condition is true,
i.e. either condition1 or condition2 is True.
Syntax: SELECT * FROM <Relation name> WHERE condition 1 OR condition2 OR…
conditionN;
AND: The AND operator allows you to filter data based on multiple conditions, all of
which must be true for the record to be included in the result set.
Syntax: SELECT * FROM <Relation name> WHERE condition 1 AND condition2 AND
…conditionN;
IN: The IN operator allows you to specify multiple values in a WHERE clause. The
IN operator is a shorthand for multiple OR conditions.
Syntax: SELECT <Attribute name>(s) FROM <Relation name> WHERE <Attribute
name> IN (value1, value2, ...);
BETWEEN: The BETWEEN operator selects values within a given range. The
values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and
end values are included.
Syntax: SELECT <Attribute name>(s) FROM <Relation name> WHERE <Attribute
name> BETWEEN value1 AND value2;
LIKE: The LIKE operator is used in a WHERE clause to search for a specified
pattern in a column. The percent sign % represents zero, one, or multiple characters.
The underscore sign _ represents one, single character.
Syntax: SELECT <Attribute name1>,<Attribute name2>, ... FROM <Relation name>
WHERE <Attribute nameN> LIKE pattern;
2. AGGREGATE FUNCTIONS
AVERAGE: avg
MINIMUM: min
MAXIMUM: max
TOTAL: sum
COUNT: count
EXECUTION
SELECT USING OR & AND
SQL> select * from batsman where country = 'India' or country = 'Australia';
SELECT USING IN
SQL> select * from batsman where country in ('WestIndies','SouthAfric','Australia');
AGGREGATE FUNCTIONS
SQL> select max(avg) from batsman;
SQL> select sum(runs), country from batsman group by country having sum(runs) >
12000;
SQL> select sum(runs), country from batsman group by country having sum(runs) >
12000 order by country;
SQL> select sum(runs), country from batsman group by country having sum(runs) >
12000 order by country desc;