Sistemas

Solo disponible en BuenasTareas
  • Páginas : 3 (594 palabras )
  • Descarga(s) : 0
  • Publicado : 12 de febrero de 2011
Leer documento completo
Vista previa del texto
SQL SELECT statements

SELECT identifies what columns.
FROM identifies which table.

SQL>SELECT[DISTINCT] {*, column [alias],...}
FROMtable;

Arithmetic Expressions(* / + - )SQL> SELECT ename, sal, 12*sal+100
2 FROM emp;

Using Column Aliases

SQL> SELECT ename AS name, sal salary
2 FROM emp;

SQL> SELECT ename "Name", sal*12 "Annual Salary"
2 FROMemp;///Comillas respeta mayuscualas y minusculas y cuando son varias palabras

Using the Concatenation Operator

SQL> SELECTename||job AS "Employees"
2 FROM emp;

Using Literal CharacterStrings

SQL> SELECT ename||' is a '||job AS "Employee Details"
2 FROM emp;

Eliminating Duplicate Rows

SQL>SELECT DISTINCT deptno
2 FROM emp;

Restricting DataSELECT[DISTINCT] {*| column [alias], ...}
FROM table
[WHEREcondition(s)];*/[opcionales]*/

Character Strings and Dates

Character strings and date values are enclosed in single quotation marks.
Thedefault date format is DD-MON-YY

SQL> SELECT ename, job, deptno
2 FROM emp
3 WHERE job='CLERK';

Comparison Operators(= >, <, >=, <, <=, <>)

SQL> SELECT ename,sal, comm
2 FROM emp
3 WHERE sal<=comm;

Other Comparison Operators(BETWEEN...AND... , IN(list) , LIKE, IS NULL)

BETWEEN...AND...
SQL> SELECTename, sal
2 FROM emp
3WHEREsal BETWEEN 1000 AND 1500;
(lower) (higher limit)

IN(list)
SQL> SELECTempno, ename, sal, mgr
2 FROM emp
3 WHEREmgr IN (7902, 7566, 7788);

LIKE
SQL> SELECTename
2 FROM emp3 WHEREename LIKE 'S%';// (%) denotes zero or many characters, (_)denote one character

IS NULL

SQL> SELECT ename, mgr
2 FROM emp
3 WHERE mgr IS NULL;

Logical Operators(AND ,OR, NOT)

AND ó OR
SQL> SELECT empno, ename, job, sal
2 FROM emp
3 WHERE sal>=1100
4 AND job='CLERK';
NOT
SQL> SELECT ename, job
2 FROM emp
3 WHERE job NOT IN...
tracking img