CC106 - MySQL
CC106 - MySQL
DB
MySQL ORDER BY
The ORDER BY keyword is used to sort the result-set in ascending or descending
order.
The ORDER BY keyword sorts the records in ascending order by default. To sort
the records in descending order, use the DESC keyword.
DB
MySQL Aliases
Aliases are used to give a table, or a column in a table, a temporary name.
DB
To display NAME AND DESIGNATION of those employees whose SG is either 'S02' or 'S03'
Another solution
DB
MySQL IN Operator
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
DB
To display NAME AND DESIGNATION of those employees whose salary less than 25000
DB
MySQL MIN() and MAX()
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
SELECT MIN(column_name)
SELECT MAX(column_name)
FROM table_name
FROM table_name
WHERE condition;
WHERE condition;
Select sum(salary), avg(salary) from SALGRADE;
DB
To display details of all transactions of TYPE Withdraw from TRANSACT table
DB
To display ANO, ANAME, AMOUNT and DOT of those persons from ACCOUNT and
TRANSACT table who have done transaction less than or equal to 3000
To display first date of transaction (DOT) from table TRANSACT for Account having ANO
as 102
DB
To display first date of transaction (DOT) from table TRANSACT for Account having ANO
as 102
DB
MySQL Aliases
MySQL Aliases
SELECT COUNT(*), SUM(AMOUNT) FROM TRANSACT
WHERE DOT <= '2023-10-12';
MySQL COUNT(), AVG() and SUM() Functions
The COUNT() function returns the SELECT COUNT(column_name)
number of rows that matches a FROM table_name
WHERE condition;
specified criterion.
The AVG() function returns the SELECT AVG(column_name)
FROM table_name
average value of a numeric WHERE condition;
column.
SELECT SUM(column_name)
The SUM() function returns the FROM table_name
total sum of a numeric column. WHERE condition;
EXAMPLE
To display Name and Price of all the Accessories in ascending order of their Price
DB
To display ID and SNAME of all the Shoppe location in 'Tangub'
DB
SELECT id, sname FROM shoppe WHERE NOT area='Tangub';
DB
To display Name, Minimum and Maximum Price of each Name from ACCESSORIES table
DB
MySQL MIN() and MAX()
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
SELECT MIN(column_name)
SELECT MAX(column_name)
FROM table_name
FROM table_name
WHERE condition;
WHERE condition;
SELECT AVG(PRICE), MAX(PRICE) FROM ACCESSORIES WHERE PRICE>=10000;
DB