Вы находитесь на странице: 1из 15

SQL Course 2.

com
http://www.sqlcourse2.com/select2.html

CREATE TABLE myemployees_af2101 (firstname, lastname, title, age, salary);

INSERT INTO myemployees_af2101 (firstname, lastname, title, age, salary) values ('Jonie',
'Weber', 'Secretary', 28, 19500.00) AND values ('Potsy', Weber', 'Programmer', 32, 45300.00)
AND values ('Dirk', 'Smith', 'Programmer II', 45, 75020.00);

UPDATE myemployees_ts0211 set salary=salary+3500 where salary<30000;

UPDATE myemployees_ts0211 set salary=salary+4500 where salary>33500;

UPDATE myemployees_ts0211 SET title='Programmer II' where title='Programmer';

Delete from myemployees_ts0211 where firstname='Jonie' and lastname='Weber-Williams';

Delete from myemployees_ts0211 where salary>70000;

Con la instrucción “Delete from” seguida del nombre de la tabla se eliminan todos los
registros, pero se conserva la tabla con las columnas y las limitaciones de caracteres.

Por el contrario, “Drop table” seguida del nombre de la tabla elimina la definición de la tabla y
sus filas.

Drop table myemployees_ts0211;

Drop table if exists agenda;

Show tables;

Describe agenda;
SELECT item, price FROM items_ordered where customerid=10449;

SELECT*FROM items_ordered where item='Tent';

SELECT customerid, order_date, item FROM items_ordered where item LIKE'S%';


SELECT DISTINCT item FROM items_ordered;

SELECT*FROM items_ordered where quantity>=2;


SELECT MAX(price) FROM items_ordered;

SELECT AVG(price) FROM items_ordered WHERE order_date LIKE '%DEC%';

SELECT COUNT(*) FROM items_ordered;

SELECT MIN(price) FROM items_ordered where item='Tent';

SELECT quantity, max(price) FROM items_ordered GROUP BY quantity;

SELECT COUNT(*), state FROM customers GROUP BY state;


SELECT item, MAX(price), MIN(price) FROM items_ordered GROUP BY item;
SELECT customerid, COUNT(customerid), SUM(price) FROM items_ordered GROUP BY
customerid;

O bien

SELECT customerid, COUNT(*), SUM(price) FROM items_ordered GROUP BY customerid;

SELECT COUNT(*), state FROM customers GROUP BY state HAVING COUNT(*)>1;

SELECT item, MAX(price), MIN(price) FROM items_ordered GROUP BY item HAVING


MAX(price)>190.00;
SELECT customerid, COUNT(*), SUM(price) FROM items_ordered GROUP BY customerid
HAVING COUNT(item)>1;

O bien

SELECT customerid, COUNT(*), SUM(price) FROM items_ordered GROUP BY customerid


HAVING COUNT(*)>1;

SELECT lastname, firstname, city FROM customers ORDER BY lastname ASC;

O bien

SELECT lastname, firstname, city FROM customers ORDER BY 1;


SELECT lastname, firstname, city FROM customers ORDER BY 1 DESC;
SELECT item, price FROM items_ordered WHERE price>10.00 ORDER BY price;
SELECT customerid, order_date, item FROM items_ordered WHERE (item <>'Snow Shoes') OR
(item <>'Ear Muffs');
SELECT item, price FROM items_ordered WHERE (item LIKE'S%') OR (item LIKE'P%') OR (item
LIKE 'F%');

SELECT order_date, item, price FROM items_ordered WHERE price BETWEEN 10.00 AND 80.00
ORDER BY price;
SELECT firstname, city, state FROM customers WHERE state IN ('Arizona','Washington',

'Oklahoma', 'Colorado', 'Hawaii');

SELECT item,SUM(price)/SUM(quantity)FROM items_ordered GROUP BY item;


SELECT customers.customerid, customers.firstname, customers.lastname,
items_ordered.order_date, items_ordered.item, items.ordered.price FROM customers INNER
JOIN items_ordered ON customers.customersid=items_ordered.customersid;

O bien

SELECT customers.customerid, customers.firstname, customers.lastname,


items_ordered.order_date, items_ordered.item, items_ordered.price
FROM customers, items_ordered WHERE customers.customerid = items_ordered.customerid;

SELECT customers.customerid, customers.firstname, customers.lastname,

items_ordered.order_date, items_ordered.item, items_ordered.price

FROM customers, items_ordered

WHERE customers.customerid = items_ordered.customerid ORDER BY customers.state DESC;


Bibliografía

SQLCourse.com - This is the original SQL Tutorial site that allows you to practice what you learn
on-line including: creating tables, inserting, updating, deleting, and dropping.

dbaSupport.com - A complete guide for Oracle dbas, including study guides, Oracle news, and
online discussions

Technology & Programming Tutorials Includes: C/C++ - Pascal - Perl - Python - Ada - Fortran -
Java - JavaScript - Game Programming - MUDs - Assembly Language - Linux - vi - GIMP - GTK+ -
vi - HTML - Sound & Music - Electronics - Science

A Gentle Introduction to SQL

UnixTools's list of Useful Free & Shareware Tutorials. Includes: Unix, Systems Administration,
Perl, Java, SQL

Gary Beene's VISUAL BASIC WORLD This site contains over 250 URLs of Visual Basic
Information as well as a very nice on-line Visual Basic Tutorial

sqlwire.com - Excellent/Free Resources to the SQL Community