SELECT(DISTINCT) {column_name} ((as) ALIAS) FROM {table_name} ORDERBY {column_name} (ASC, DESC)
ASC
by asending order (default)
DESC
by desending order
1
SELECT empno, name, job FROM employee orderbynamedesc;
Using WHERE
1 2
SELECT(DISTINCT) {column_name} FROM {table_name} WHERE {contidion} ORDERBY {column_name orstatement} (ASC, DESC)
1
SELECTname, hiredate, FROM employee WHERE hiredate < '1981-01-01';
1 2 3 4
SELECTname, deptno FROM employee WHERE deptno in (10, 30); SELECTname, deptno FROM employee WHERE deptno = 10or deptno = 30; SELECT * from employee WHERE deptno = 10and salary < 1500; SELECT * from employee WHERE deptno = 30and salary < 1500;
LIKE keyword
using wildcard to select pattern string
%: 0-9a-zA-Z several charactor
_: single charactor
1
SELECT * FROM employee WHEREnameLIKE'A%'
1
SELECT * FROM employee WHEREnamelike'_A%';
1
SELECT * FROM employee WHEREnamelike'%A%';
Using SQL function
UCASE, UPPER
1
SELECTUPPER('SEoul'), UCASE('seOUL`);
LCASE, LOWER
1
SELECTlower(name) FROM employee;
SUBSTRING
1
SELECTSUBSTRING('Happy Day', 3, 2);
LPAD, RPAD
1
SELECTLPAD('hi', 5, '?'), LPAD('joe', '7', '*');
TRIM, LTRIM, RTRIM
1
SELECTLTRIM(' hello '), RTRIM(' hello ');
ABS(x)
MOD(n, m)
CAST: type casting CAST(expression AS type)
Group function
COUNT()
COUNT(DISTINCT)
AVG()
MIN()
MAX()
SUM()
GROUP_CONCAT()
VARIANCE()
STDEV()
Using group function with group by clause
1
SELECT deptno, avg(salary), sum(salary) FROM employee GROUPBY deptno;