Professional Documents
Culture Documents
MODIFICAR DATOS
INSERT INTO clients(name, email, birthdate, gender, active)
VALUES ('Carlos Quejada','bizzyrap31@gmail.com','1990-09-13','M',0)
ON DUPLICATE KEY UPDATE active=VALUES(active);
modificar datos
UPDATE books SET year = 2002 where book_id =2;
eliminar datos
delete from books where book_id = 3;
ejemplo)))))))))))))))))))))
DELETE FROM usuarios
WHERE edad >35
ORDER BY edad
LIMIT 15
)))))))))))))))))))))))))))
INSERT INTO transactions(transaction_id,book_id,client_id,type,finished)
VALUES(1,12,34,'sell',1),
(2,54,87,'lend',0),
(3,3,14,'sell',1),
(4,1,54,'sell',1),
(5,12,81,'lend',1),
(6,12,81,'return',1),
(7,87,29,'sell',1);
condicion where por hay nacionalidades nulas, cuando usemos la funcion count se
debe agrupar con primari key y otro campo
select nationality, count(author_id)
from authors
where nationality IS NOT NULL
group by nationality
order by nationality ;
cuantos libros hay de cada nacionalidad
select a.nationality, count(b.book_id) as num_libros
from authors as a
join books as b
on a.author_id = b.author_id
where nationality IS NOT NULL
group by a.nationality
order by num_libros desc, a.nationality;
select nationality,
count(book_id) as libros,
Avg(price) as promedio,
stddev(price) as desviacion
from books as b
JOIN authors as a ON a.author_id = b.author_id
group by nationality
order by libros desc;
idem pero con nacionalidad
cual es el precion maximo / minimo
select nationality,MAX(price),MIN(price)
from books as b
join authors as a on a.author_id = b.author_id
group by nationality;
como quedario el reporte de prestamos
modificar datos
estructura
UPDATE tabla
SET
(columna = valor,......)
WHERE (codicions ) IN (,) para varios
LIMIT 1 ;
update clients set active = 0 where client_id = 80 limit 1
UPDATE clients
SET active = 0
WHERE client_id IN (1,6,8,7,5,6) OR name like '%Lope%';
TRUNCATE nameTable;
TRUNCATE nameTable;
elimina tabla
DROP nameTable;
DROP nameTable;
UPDATE authors
SET nationality = 'GBR'
WHERE nationaliTy = 'ENG';
contar registro con las funciones count y sum agregar 1 dentro del parentesis
select count(book_id), sum(1) from books ;
eliminar columna
alter table authors drop column birthyear ;