Professional Documents
Culture Documents
Practicas de Mysql Ya
Practicas de Mysql Ya
+-----------+-------------+------+-----+---------+-------+
| nombre
| varchar(20) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| telefono | varchar(11) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql>
4 - Carga de registros a una tabla y su recuperacin (insert into - select)
mysql> drop table agenda;
Query OK, 0 rows affected (0.00 sec)
mysql> show table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> show tables;
Empty set (0.00 sec)
mysql>
mysql> use practica;
Database changed
mysql> create table agenda(
-> nombre varchar(20),
-> domicilio varchar(30),
-> telefono varchar(11)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> describe agenda;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| nombre
| varchar(20) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| telefono | varchar(11) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> insert into agenda(nombre,domicilio,telefono) values('alberto morales','c
olon 123','4234567');
Query OK, 1 row affected (0.02 sec)
mysql> insert into agenda(nombre,domicilio,telefono) values('juan torres','avell
aneda','135','4458787');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into agenda(nombre,domicilio,telefono) values('juan torres','avell
aneda 135','4458787');
Query OK, 1 row affected (0.01 sec)
mysql> select nombre,domicilio,telefono from agenda;
+-----------------+----------------+----------+
| nombre
| domicilio
| telefono |
+-----------------+----------------+----------+
| alberto morales | colon 123
| 4234567 |
| juan torres
| avellaneda 135 | 4458787 |
+-----------------+----------------+----------+
2 rows in set (0.00 sec)
mysql> select*from agenda;
+-----------------+----------------+----------+
| nombre
| domicilio
| telefono |
+-----------------+----------------+----------+
| alberto morales | colon 123
| 4234567 |
| juan torres
| avellaneda 135 | 4458787 |
+-----------------+----------------+----------+
2 rows in set (0.00 sec)
mysql> drop table agenda;
Query OK, 0 rows affected (0.01 sec)
mysql> show table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> show tables;
Empty set (0.01 sec)
mysql>
5 - Tpos de datos bsicos de un campo de una tabla.
mysql> drop table if exists peliculas;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> drop table if exists peliculas;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> usb practica;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'usb p
ractica' at line 1
mysql> use practica;
Database changed
mysql> create table peliculas(
-> nombre varchar(20),
-> actor varchar(20),
-> duracion integer,
-> cantidad integer
-> );
Query OK, 0 rows affected (0.38 sec)
mysql> describe peliculas;
+----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| nombre | varchar(20) | YES |
| NULL
|
|
| actor
| varchar(20) | YES |
| NULL
|
|
| duracion | int(11)
| YES |
| NULL
|
|
| cantidad | int(11)
| YES |
| NULL
|
|
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
+--------------------+----------+
5 rows in set (0.02 sec)
7 - Recuperacin de registros especficos (select - where)
mysql> drop table if exists agenda;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> use practica;
Database changed
mysql> create table agenda(
-> nombre varchar(20),
-> domicilio varchar(30),
-> telefono varchar(11)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> describe agenda;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| nombre
| varchar(20) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| telefono | varchar(11) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> insert into agenda(nombre,domicilio,telefono) values('alberto morales','c
olon 123','4234567');
Query OK, 1 row affected (0.00 sec)
mysql> insert into agenda(nombre,domicilio,telefono) values('juan torres','avell
aneda 135','4458787');
Query OK, 1 row affected (0.01 sec)
mysql> insert into agenda(nombre,domicilio,telefono) values('fernando lopez','ur
quia 333','4545454');
Query OK, 1 row affected (0.01 sec)
mysql> select*from agenda;
+-----------------+----------------+----------+
| nombre
| domicilio
| telefono |
+-----------------+----------------+----------+
| alberto morales | colon 123
| 4234567 |
| juan torres
| avellaneda 135 | 4458787 |
| fernando lopez | urquia 333
| 4545454 |
+-----------------+----------------+----------+
3 rows in set (0.00 sec)
mysql> select nombre from agenda;
+-----------------+
| nombre
|
+-----------------+
| alberto morales |
| juan torres
|
| fernando lopez |
+-----------------+
3 rows in set (0.00 sec)
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> insert into articulo(codigo,nombre,descripcion,precio,cantidad) values(1,
'impresora','Epson Stylus C45',400.80,20);
Query OK, 1 row affected (0.01 sec)
mysql> insert into articulo(codigo,nombre,descripcion,precio,cantidad) values(2,
'impresora','Epson Stylus C85',500,30);
Query OK, 1 row affected (0.00 sec)
mysql> insert into articulos (codigo, nombre, descripcion, precio,cantidad)
-> values (3,'monitor','Samsung 14',800,10);
ERROR 1146 (42S02): Table 'practica.articulos' doesn't exist
mysql> insert into articulo(codigo,nombre,descripcion,precio,cantidad) values(3,
'monitor','Samsung 14',800,10);
Query OK, 1 row affected (0.01 sec)
mysql> insert into articulo(codigo,nombre,descripcion,precio,cantidad) values(4,
'teclado','ingles Biswal',100,50);
Query OK, 1 row affected (0.01 sec)
mysql> select*from articulo;
+--------+-----------+------------------+--------+----------+
| codigo | nombre
| descripcion
| precio | cantidad |
+--------+-----------+------------------+--------+----------+
|
1 | impresora | Epson Stylus C45 | 400.8 |
20 |
|
2 | impresora | Epson Stylus C85 |
500 |
30 |
|
3 | monitor | Samsung 14
|
800 |
10 |
|
4 | teclado | ingles Biswal
|
100 |
50 |
+--------+-----------+------------------+--------+----------+
4 rows in set (0.00 sec)
mysql> select*from articulo;
+--------+-----------+------------------+--------+----------+
| codigo | nombre
| descripcion
| precio | cantidad |
+--------+-----------+------------------+--------+----------+
|
1 | impresora | Epson Stylus C45 | 400.8 |
20 |
|
2 | impresora | Epson Stylus C85 |
500 |
30 |
|
3 | monitor | Samsung 14
|
800 |
10 |
|
4 | teclado | ingles Biswal
|
100 |
50 |
+--------+-----------+------------------+--------+----------+
4 rows in set (0.00 sec)
mysql> select*from articulo
-> where precio>=500;
+--------+-----------+------------------+--------+----------+
| codigo | nombre
| descripcion
| precio | cantidad |
+--------+-----------+------------------+--------+----------+
|
2 | impresora | Epson Stylus C85 |
500 |
30 |
|
3 | monitor | Samsung 14
|
800 |
10 |
+--------+-----------+------------------+--------+----------+
2 rows in set (0.00 sec)
mysql> select nombre,descripcion,precio,cantidad from articulo
;
+---------+-------------+--------+----------+
| nombre | descripcion | precio | cantidad |
+---------+-------------+--------+----------+
| monitor | Samsung 14 |
800 |
10 |
+---------+-------------+--------+----------+
1 row in set (0.00 sec)
mysql> select nombre,descripcion from articulo where precio<>10
+-----------+------------------+
| nombre
| descripcion
|
+-----------+------------------+
| impresora | Epson Stylus C45 |
| impresora | Epson Stylus C85 |
| monitor | Samsung 14
|
+-----------+------------------+
3 rows in set (0.00 sec)
9 - Borrado de registros de una tabla (delete)
mysql> describe agenda;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| apellido | varchar(30) | YES |
| NULL
|
|
| nombre
| varchar(30) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| telefono | varchar(11) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.11 sec)
mysql> select*from agenda;
Empty set (0.00 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('mores','a
lberto','colon 123','4234567');
Query OK, 1 row affected (0.03 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('torres','
juan','avellaneda 135','4458787');
Query OK, 1 row affected (0.02 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('lopez','m
aria','urquia 333','4545454');
Query OK, 1 row affected (0.00 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('peralta',
'susana','gral. paz 1234','4123456');
Query OK, 1 row affected (0.02 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('lopez','j
ose','urquia 333','4545454');
Query OK, 1 row affected (0.01 sec)
mysql> describe agenda;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| apellido | varchar(30) | YES |
| NULL
|
|
| nombre
| varchar(30) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| telefono | varchar(11) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select*from agenda;
+----------+---------+----------------+----------+
| apellido | nombre | domicilio
| telefono |
+----------+---------+----------------+----------+
| mores
| alberto | colon 123
| 4234567 |
| torres | juan
| avellaneda 135 | 4458787 |
| lopez
| maria | urquia 333
| 4545454 |
| peralta | susana | gral. paz 1234 | 4123456 |
| lopez
| jose
| urquia 333
| 4545454 |
+----------+---------+----------------+----------+
5 rows in set (0.00 sec)
mysql> delete from agenda where nombre='juan';
Query OK, 1 row affected (0.02 sec)
mysql> select*from agenda;
+----------+---------+----------------+----------+
| apellido | nombre | domicilio
| telefono |
+----------+---------+----------------+----------+
| mores
| alberto | colon 123
| 4234567 |
| lopez
| maria | urquia 333
| 4545454 |
| peralta | susana | gral. paz 1234 | 4123456 |
| lopez
| jose
| urquia 333
| 4545454 |
+----------+---------+----------------+----------+
4 rows in set (0.00 sec)
mysql> delete from agenda where telefono='4545454';
Query OK, 2 rows affected (0.00 sec)
mysql> select*from agenda;
+----------+---------+----------------+----------+
| apellido | nombre | domicilio
| telefono |
+----------+---------+----------------+----------+
| mores
| alberto | colon 123
| 4234567 |
| peralta | susana | gral. paz 1234 | 4123456 |
+----------+---------+----------------+----------+
2 rows in set (0.00 sec)
+--------------------+
| Tables_in_practica |
+--------------------+
| agenda
|
| articulo
|
| peliculas
|
+--------------------+
3 rows in set (0.00 sec)
mysql> drop table agenda;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+--------------------+
| Tables_in_practica |
+--------------------+
| articulo
|
| peliculas
|
+--------------------+
2 rows in set (0.00 sec)
mysql> use practica;
Database changed
mysql> create table agenda(
-> apellido varchar(30),
-> nombre varchar(20),
-> domicilio varchar(30),
-> telefono varchar(11)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe agenda;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| apellido | varchar(30) | YES |
| NULL
|
|
| nombre
| varchar(20) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| telefono | varchar(11) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('morales','
alberto','colon 123','4234567');
Query OK, 1 row affected (0.00 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('torres','j
uan','avellaneda 135','4458787');
Query OK, 1 row affected (0.01 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('lopez','ma
riana','urquiza 333','4545454');
Query OK, 1 row affected (0.01 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('lopez','jo
se','urquizan 333','4545454');
Query OK, 1 row affected (0.01 sec)
mysql> insert into agenda(apellido,nombre,domicilio,telefono) values('peralta','
susana','gral. paz 1234','4123456');
Query OK, 1 row affected (0.01 sec)
| peralta | susana
| gral. paz 1234 | 4123456 |
+----------+-----------+----------------+----------+
5 rows in set (0.00 sec)
11 - Clave primaria.
mysql> use practica;
Database changed
mysql> create table libro(
-> codigo integer,
-> titulo varchar(20),
-> autor varchar(30),
-> editorial varchar(15),
-> primary key(codigo)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe libro;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| codigo
| int(11)
| NO | PRI | 0
|
|
| titulo
| varchar(20) | YES |
| NULL
|
|
| autor
| varchar(30) | YES |
| NULL
|
|
| editorial | varchar(15) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
4 rows in set (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(1,'el leph','bor
es','planeta');
Query OK, 1 row affected (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(2,'martin fierro
,'jose hernandez','emece');
Query OK, 1 row affected (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(4,'cervante elqui
jote','borges','paidos');
Query OK, 1 row affected (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(3,'aprende php','
mario molina','emece');
Query OK, 1 row affected (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(5,'matematica est
as ahi','paenza','paidos');
Query OK, 1 row affected (0.00 sec)
mysql> select*from libro;
+--------+----------------------+----------------+-----------+
| codigo | titulo
| autor
| editorial |
+--------+----------------------+----------------+-----------+
|
1 | el leph
| borges
| planeta |
|
2 | martin fierro
| jose hernandez | emece
|
|
3 | aprende php
| mario molina | emece
|
|
4 | cervante elquijote | borges
| paidos
|
|
5 | matematica estas ahi | paenza
| paidos
|
+--------+----------------------+----------------+-----------+
5 rows in set (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(6,'ecologia','mar
io molina','gamuza');
Query OK, 1 row affected (0.00 sec)
mysql> select*from libro;
+--------+----------------------+----------------+-----------+
| codigo | titulo
| autor
| editorial |
+--------+----------------------+----------------+-----------+
|
1 | el leph
| borges
| planeta |
|
2 | martin fierro
| jose hernandez | emece
|
|
3 | aprende php
| mario molina | emece
|
|
4 | cervante elquijote | borges
| paidos
|
|
5 | matematica estas ahi | paenza
| paidos
|
|
6 | ecologia
| mario molina | gamuza
|
+--------+----------------------+----------------+-----------+
6 rows in set (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(7,'ecologia','men
dez mendez','paidos');
Query OK, 1 row affected (0.00 sec)
mysql> select*from libro;
+--------+----------------------+----------------+-----------+
| codigo | titulo
| autor
| editorial |
+--------+----------------------+----------------+-----------+
|
1 | el leph
| borges
| planeta |
|
2 | martin fierro
| jose hernandez | emece
|
|
3 | aprende php
| mario molina | emece
|
|
4 | cervante elquijote | borges
| paidos
|
|
5 | matematica estas ahi | paenza
| paidos
|
|
6 | ecologia
| mario molina | gamuza
|
|
7 | ecologia
| mendez mendez | paidos
|
+--------+----------------------+----------------+-----------+
7 rows in set (0.00 sec)
mysql> insert into libro(codigo,titulo,autor,editorial) values(7,'ecuaciones','m
endez camilla','chep','mendes');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql>
12 - Campo entero con autoincremento.
| codigo
| int(11)
| NO | PRI | NULL
| auto_increment |
| nombre
| varchar(20) | YES |
| NULL
|
|
| laboratorio | varchar(20) | YES |
| NULL
|
|
| precio
| float
| YES |
| NULL
|
|
| cantidad
| int(11)
| YES |
| NULL
|
|
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> insert into medicamentos(codigo,nombre,laboratorio,precio,cantidad) value
s(12,'paracetamol 500','bago',1.90,200);
Query OK, 1 row affected (0.00 sec)
mysql> describe medicamentos;
+-------------+-------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-------------+-------------+------+-----+---------+----------------+
| codigo
| int(11)
| NO | PRI | NULL
| auto_increment |
| nombre
| varchar(20) | YES |
| NULL
|
|
| laboratorio | varchar(20) | YES |
| NULL
|
|
| precio
| float
| YES |
| NULL
|
|
| cantidad
| int(11)
| YES |
| NULL
|
|
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> select * from medicamentos;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
1 | Sertal
| Roche
|
5.2 |
100 |
|
2 | Buscapina
| Roche
|
4.1 |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
100 |
|
4 | Amoxidal 500
| Bayer
| 15.6 |
100 |
|
12 | paracetamol 500 | bago
|
1.9 |
200 |
+--------+-----------------+-------------+--------+----------+
5 rows in set (0.00 sec)
mysql> insert into medicamentos(nombre,laboratorio,precio,cantidad) values('baya
sperina','bayer',2.10,150);
Query OK, 1 row affected (0.00 sec)
mysql> select * from medicamentos;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
1 | Sertal
| Roche
|
5.2 |
100 |
|
2 | Buscapina
| Roche
|
4.1 |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
100 |
|
4 | Amoxidal 500
| Bayer
| 15.6 |
100 |
|
12 | paracetamol 500 | bago
|
1.9 |
200 |
|
13 | bayasperina
| bayer
|
2.1 |
150 |
+--------+-----------------+-------------+--------+----------+
6 rows in set (0.02 sec)
13 - Comando truncate table.
mysql> use practica;
Database changed
mysql> create table medicamentos(
-> codigo integer auto_increment,
14 - Valores null.
mysql> use practica;
Database changed
mysql> create table medicamentos(
-> codigo integer auto_increment,
-> nombre varchar(20),
-> laboratorio varchar(20),
-> precio float,
-> cantidad integer,
-> primary key(codigo)
-> );
Query OK, 0 rows affected (0.37 sec)
mysql> describe medicamentos;
+-------------+-------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-------------+-------------+------+-----+---------+----------------+
| codigo
| int(11)
| NO | PRI | NULL
| auto_increment |
| nombre
| varchar(20) | YES |
| NULL
|
|
| laboratorio | varchar(20) | YES |
| NULL
|
|
| precio
| float
| YES |
| NULL
|
|
| cantidad
| int(11)
| YES |
| NULL
|
|
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> insert into medicamentos(nombre,laboratorio,precio,cantidad) values('ser
tal','roche',5.2,100);
Query OK, 1 row affected (0.02 sec)
mysql> insert into medicamentos(nombre,laboratorio,precio,cantidad) values('bus
capina','roche',4.10,200);
Query OK, 1 row affected (0.01 sec)
mysql> insert into medicamentos(nombre,laboratorio,precio,cantidad) values('amo
xilina 500','bayer',15.60,100);
Query OK, 1 row affected (0.00 sec)
+--------+-----------+-------------+--------+----------+
|
2 | Buscapina | Roche
| NULL |
200 |
+--------+-----------+-------------+--------+----------+
1 row in set (0.00 sec)
mysql> select*from medicamentos where precio='0';
+--------+-------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-------------+-------------+--------+----------+
|
6 | Bayaspirina |
|
0 |
150 |
+--------+-------------+-------------+--------+----------+
1 row in set (0.01 sec)
mysql> insert into medicamentos (nombre,laboratorio,precio,cantidad) values(null
,'bayes',10.20,100);
ERROR 1048 (23000): Column 'nombre' cannot be null
mysql> insert into medicamentos (nombre,laboratorio,precio,cantidad) values(null
,'bayes',10.20,100);
ERROR 1048 (23000): Column 'nombre' cannot be null
mysql> insert into medicamentos (nombre,laboratorio,precio,cantidad) values(null
,'bayes',10.20,100);
ERROR 1048 (23000): Column 'nombre' cannot be null
mysql> select*from medicamentos;
+--------+------------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+------------------+-------------+--------+----------+
|
1 | Sertal compuesto | Roche
|
7.1 |
150 |
|
2 | Buscapina
| Roche
| NULL |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
0 |
|
4 | Amoxidal jarabe | Bayer
|
25 |
120 |
|
5 | Amoxinil
| NULL
|
25 |
120 |
|
6 | Bayaspirina
|
|
0 |
150 |
+--------+------------------+-------------+--------+----------+
6 rows in set (0.00 sec)
mysql> select*from medicamentos where precio<>0;
+--------+------------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+------------------+-------------+--------+----------+
|
1 | Sertal compuesto | Roche
|
7.1 |
150 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
0 |
|
4 | Amoxidal jarabe | Bayer
|
25 |
120 |
|
5 | Amoxinil
| NULL
|
25 |
120 |
+--------+------------------+-------------+--------+----------+
4 rows in set (0.00 sec)
mysql> select*from medicamentos where precio is not null;
+--------+------------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+------------------+-------------+--------+----------+
|
1 | Sertal compuesto | Roche
|
7.1 |
150 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
0 |
|
4 | Amoxidal jarabe | Bayer
|
25 |
120 |
|
5 | Amoxinil
| NULL
|
25 |
120 |
|
6 | Bayaspirina
|
|
0 |
150 |
+--------+------------------+-------------+--------+----------+
5 rows in set (0.00 sec)
mysql> select*from medicamentos where laboratorio<>'';
+--------+------------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+------------------+-------------+--------+----------+
|
1 | Sertal compuesto | Roche
|
7.1 |
150 |
|
2 | Buscapina
| Roche
| NULL |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
0 |
|
4 | Amoxidal jarabe | Bayer
|
25 |
120 |
+--------+------------------+-------------+--------+----------+
4 rows in set (0.00 sec)
mysql> select*from medicamentos where laboratorio is not null;
+--------+------------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+------------------+-------------+--------+----------+
|
1 | Sertal compuesto | Roche
|
7.1 |
150 |
|
2 | Buscapina
| Roche
| NULL |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.6 |
0 |
|
4 | Amoxidal jarabe | Bayer
|
25 |
120 |
|
6 | Bayaspirina
|
|
0 |
150 |
+--------+------------------+-------------+--------+----------+
5 rows in set (0.00 sec)
mysql>
| patente | marca
| modelo | precio |
+---------+--------------+--------+--------+
| ACG234 | Renault 11 | 1990 | 40000 |
| BCD333 | Peugeot 505 | 1990 | 80000 |
| GCD123 | Renault Clio | 1990 | 70000 |cre
+---------+--------------+--------+--------+
3 rows in set (0.00 sec)
mysql> select * from autos where precio>50000;
+---------+----------------+--------+--------+
| patente | marca
| modelo | precio |
+---------+----------------+--------+--------+
| BCC333 | Renault Megane | 1998 | 95000 |
| BCD333 | Peugeot 505
| 1990 | 80000 |
| GCD123 | Renault Clio | 1990 | 70000 |
+---------+----------------+--------+--------+
3 rows in set (0.00 sec)
mysql>
18 - Tipos de datos (numricos)
mysql> use practica;
Database changed
mysql> create table pedido(
-> numeropedido integer unsigned auto_increment,
-> nombre varchar(20),
-> tipo varchar(30),
-> precio float unsigned,
-> cantidad integer unsigned,
-> domicilio varchar(15),
-> primary key(numeropedido)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> describe pedido;
+--------------+------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+--------------+------------------+------+-----+---------+----------------+
| numeropedido | int(10) unsigned | NO | PRI | NULL
| auto_increment |
| nombre
| varchar(20)
| YES |
| NULL
|
|
| tipo
| varchar(30)
| YES |
| NULL
|
|
| precio
| float unsigned | YES |
| NULL
|
|
| cantidad
| int(10) unsigned | YES |
| NULL
|
|
| domicilio
| varchar(15)
| YES |
| NULL
|
|
+--------------+------------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
mysql>
21 - Valores invlidos.
values('arabe
values('piza'
| Type
+-----------+--------------------------+------+-----+---------+----------------+
| numero
| PRI | NULL
| auto_increment |
| documento | char(8)
| NO
| NULL
| nombre
| varchar(30)
| YES |
| NULL
| saldo
| decimal(9,2)
| YES |
| NULL
+-----------+--------------------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
mysql> select*from cuenta;
+----------+-----------+---------------+---------+
| numero | documento | nombre
| saldo |
+----------+-----------+---------------+---------+
| 00001234 | 22333444 | Juan Perez
| 2000.60 |
| 00002566 | 23333444 | Maria Pereyra | 5050.00 |
| 00005987 | 24333444 | Marcos Torres | 200.00 |
| 00014434 | 25333444 | Ana Juarez
| 8000.60 |
+----------+-----------+---------------+---------+
4 rows in set (0.00 sec)
mysql> insert into cuenta(numero,documento,nombre,saldo) values(-1234,'27333444'
,'luis duarte',2800);
ERROR 1264 (22003): Out of range value for column 'numero' at row 1
mysql> insert into cuentas (numero,documento,nombre,saldo) values(-1234,'273334
44','Luis Duarte',2800);
ERROR 1146 (42S02): Table 'practica.cuentas' doesn't exist
mysql>
24 - Columnas calculadas.
+-----------+-----------------------+------+-----+---------+----------------+
5 rows in set (0.02 sec)
mysql> insert into libros (titulo,autor,editorial,precio)
Borges','Paidos',33.4);
Query OK, 1 row affected (0.02 sec)
values('El alehp','
values('Alicia en
26 - Funciones matemticas.
+-------------------------------------+--------------------+
| titulo
| truncate(precio,1) |
+-------------------------------------+--------------------+
| El alehp
|
33.4 |
| Alicia en el pais de las maravillas |
16.3 |
| Alicia a traves del espejo
|
18.8 |
+-------------------------------------+--------------------+
3 rows in set (0.00 sec)
mysql>
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
1 | Sertal
| Roche
| 5.20 |
100 |
|
3 | Amoxidal 500
| Bayer
| 15.60 |
100 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
150 |
|
2 | Buscapina
| Roche
| 4.10 |
200 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
200 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
+--------+-----------------+-------------+--------+----------+
6 rows in set (0.00 sec)
mysql> select*from medicamentos;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
1 | Sertal
| Roche
| 5.20 |
100 |
|
2 | Buscapina
| Roche
| 4.10 |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.60 |
100 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
200 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
150 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
+--------+-----------------+-------------+--------+----------+
6 rows in set (0.00 sec)
mysql> select codigo,nombre,laboratorio,precio,cantidad from medicamentos order
by laboratorio desc,cantidad asc;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
1 | Sertal
| Roche
| 5.20 |
100 |
|
2 | Buscapina
| Roche
| 4.10 |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.60 |
100 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
150 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
200 |
+--------+-----------------+-------------+--------+----------+
6 rows in set (0.00 sec)
| nombre
| varchar(20)
| YES |
| NULL
|
|
| laboratorio | varchar(20)
| YES |
| NULL
|
|
| precio
| decimal(5,2)
| YES |
| NULL
|
|
| cantidad
| int(10) unsigned | YES |
| NULL
|
|
+-------------+------------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
mysql> insert into medicamentos (nombre, laboratorio,precio,cantidad) values('S
ertal','Roche',5.2,100);
Query OK, 1 row affected (0.01 sec)
mysql> insert into medicamentos (nombre, laboratorio,precio,cantidad) values('
Buscapina','Roche',4.10,200);
Query OK, 1 row affected (0.00 sec)
mysql> insert into medicamentos (nombre, laboratorio,precio,cantidad) values('
Amoxidal 500','Bayer',15.60,100);
Query OK, 1 row affected (0.00 sec)
mysql> insert into medicamentos (nombre, laboratorio,precio,cantidad) values('
Paracetamol 500','Bago',1.90,200);
Query OK, 1 row affected (0.00 sec)
mysql> insert into medicamentos (nombre, laboratorio,precio,cantidad) values('
Bayaspirina','Bayer',2.10,150);
Query OK, 1 row affected (0.00 sec)
mysql> insert into medicamentos (nombre, laboratorio,precio,cantidad) values('
Amoxidal jarabe','Bayer',5.10,250);
Query OK, 1 row affected (0.00 sec)
mysql> select codigo,nombre
-> from medicamentos
-> where laboratorio='roche' and
-> precio<5;
+--------+-----------+
| codigo | nombre
|
+--------+-----------+
|
2 | Buscapina |
+--------+-----------+
1 row in set (0.00 sec)
mysql> select*from medicamentos
-> where laboratorio='roche' and
-> precio<5;
+--------+-----------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------+-------------+--------+----------+
|
2 | Buscapina | Roche
| 4.10 |
200 |
+--------+-----------+-------------+--------+----------+
1 row in set (0.00 sec)
mysql> select*from medicamentos
-> where not ('bayer');
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
1 | Sertal
| Roche
| 5.20 |
100 |
|
2 | Buscapina
| Roche
| 4.10 |
200 |
|
3 | Amoxidal 500
| Bayer
| 15.60 |
100 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
200 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
150 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
+--------+-----------------+-------------+--------+----------+
6 rows in set, 1 warning (0.42 sec)
mysql> select*from medicamentos
-> where not laboratorio='bayer' and
-> not cantidad=100;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
2 | Buscapina
| Roche
| 4.10 |
200 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
200 |
+--------+-----------------+-------------+--------+----------+
2 rows in set (0.00 sec)
mysql> select*from medicamentos
-> where laboratorio='bayer' and
-> not cantidad=100;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
5 | Bayaspirina
| Bayer
| 2.10 |
150 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
+--------+-----------------+-------------+--------+----------+
2 rows in set (0.00 sec)
mysql> delete from medicamentos
-> where laboratorio='bayer' and
-> precio>10;
Query OK, 1 row affected (0.34 sec)
mysql> update medicamentos set cantidad=200
-> where laboratorio='roche' and
-> precio>5;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> delete from medicamentos
-> where laboratorio='bayer' or
-> precio<3;
Query OK, 3 rows affected (0.04 sec)
mysql> select*from medicamentos;
+--------+-----------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------+-------------+--------+----------+
|
1 | Sertal
| Roche
| 5.20 |
200 |
|
2 | Buscapina | Roche
| 4.10 |
200 |
+--------+-----------+-------------+--------+----------+
2 rows in set (0.00 sec)
30 - Otros operadores relacionales (between - in)
mysql> use practica;
Database changed
+--------+-----------------+-------------+--------+----------+
|
3 | Amoxidal 500
| Bayer
| 15.60 |
100 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
200 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
150 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
+--------+-----------------+-------------+--------+----------+
4 rows in set (0.06 sec)
mysql> delete from medicamentos
-> where cantidad between 100 and 200;
Query OK, 5 rows affected (0.04 sec)
mysql> select*from medicamentos;
+--------+-----------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+-----------------+-------------+--------+----------+
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
250 |
+--------+-----------------+-------------+--------+----------+
1 row in set (0.00 sec)
|
4 | Paracetamol 500 | Bago
| 1.90 |
+--------+-----------------+-------------+--------+
1 row in set (0.00 sec)
mysql> select codigo,nombre,laboratorio,precio
-> from medicamentos
-> where precio like '%.1%';
+--------+------------------+-------------+--------+
| codigo | nombre
| laboratorio | precio |
+--------+------------------+-------------+--------+
|
2 | Buscapina
| Roche
| 4.10 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
|
7 | Sertal compuesto | Bayer
| 5.10 |
+--------+------------------+-------------+--------+
4 rows in set (0.00 sec)
mysql> select codigo,nombre,laboratorio,precio
-> from medicamentos
-> where nombre not like'%compuesto%';
+--------+------------------+-------------+--------+
| codigo | nombre
| laboratorio | precio |
+--------+------------------+-------------+--------+
|
1 | Sertal gotas
| Roche
| 5.20 |
|
2 | Buscapina
| Roche
| 4.10 |
|
3 | Amoxidal 500
| Bayer
| 15.60 |
|
4 | Paracetamol 500 | Bago
| 1.90 |
|
5 | Bayaspirina
| Bayer
| 2.10 |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
|
8 | Paracetamol 1000 | Bago
| 2.90 |
|
9 | Amoxinil
| Roche
| 17.80 |
+--------+------------------+-------------+--------+
8 rows in set (0.01 sec)
mysql> delete from medicamentos
-> where nombre like '%y%';
Query OK, 1 row affected (0.03 sec)
mysql> update medicamentos set precio=5
-> where nombre like 'paracetamol%' and
-> precio<2;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select*from medicamentos;
+--------+------------------+-------------+--------+----------+
| codigo | nombre
| laboratorio | precio | cantidad |
+--------+------------------+-------------+--------+----------+
|
1 | Sertal gotas
| Roche
| 5.20 |
NULL |
|
2 | Buscapina
| Roche
| 4.10 |
NULL |
|
3 | Amoxidal 500
| Bayer
| 15.60 |
NULL |
|
4 | Paracetamol 500 | Bago
| 5.00 |
NULL |
|
6 | Amoxidal jarabe | Bayer
| 5.10 |
NULL |
|
7 | Sertal compuesto | Bayer
| 5.10 |
NULL |
|
8 | Paracetamol 1000 | Bago
| 2.90 |
NULL |
|
9 | Amoxinil
| Roche
| 17.80 |
NULL |
+--------+------------------+-------------+--------+----------+
8 rows in set (0.02 sec)
|
+----------+----------+----------------+------------+----------------------------+
| Perez
| Juan
| Sarmiento 345 | 4334455
| juancito@gmail.com
|
| Garcia | Ana
| Urquiza 367
| 4226677
| anamariagarcia@hotmail.co
|
| Lopez
| Juan
| Avellaneda 900 | NULL
| juancitoLopez@gmail.com
|
| Juarez | Mariana | Sucre 123
| 0525657687 | marianaJuarez2@gmail.com
|
| Molinari | Lucia
| Peru 1254
| 4590987
| molinarilucia@hotmail.com
|
| Ferreyra | Patricia | Colon 1534
| 4585858
| NULL
|
| Perez
| Susana | San Martin 333 | NULL
| NULL
|
| Perez
| Luis
| Urquiza 444
| 0354545256 | perezluisalberto@hotmail.
om |
| Lopez
| Maria
| Salta 314
| NULL
| lopezmariayo@gmail.com
|
+----------+----------+----------------+------------+----------------------------+
9 rows in set (0.00 sec)
mysql> select*from agenda
-> where apellido regexp'[v-z]';
+----------+----------+----------------+------------+----------------------------+
| apellido | nombre | domicilio
| telefono | mail
|
+----------+----------+----------------+------------+----------------------------+
| Perez
| Juan
| Sarmiento 345 | 4334455
| juancito@gmail.com
|
| Lopez
| Juan
| Avellaneda 900 | NULL
| juancitoLopez@gmail.com
|
| Juarez | Mariana | Sucre 123
| 0525657687 | marianaJuarez2@gmail.com
|
| Ferreyra | Patricia | Colon 1534
| 4585858
| NULL
|
| Perez
| Susana | San Martin 333 | NULL
| NULL
|
| Perez
| Luis
| Urquiza 444
| 0354545256 | perezluisalberto@hotmail.
om |
| Lopez
| Maria
| Salta 314
| NULL
| lopezmariayo@gmail.com
|
+----------+----------+----------------+------------+----------------------------+
7 rows in set (0.00 sec)
mysql> select*from agenda
-> where apellido regexp'ez$';
+----------+---------+----------------+------------+----------------------------+
| apellido | nombre | domicilio
| telefono | mail
|
+----------+---------+----------------+------------+----------------------------+
| Perez
| Juan
| Sarmiento 345 | 4334455
| juancito@gmail.com
|
| Lopez
| Juan
| Avellaneda 900 | NULL
| juancitoLopez@gmail.com
|
| Juarez | Mariana | Sucre 123
| 0525657687 | marianaJuarez2@gmail.com
|
| Perez
| Susana | San Martin 333 | NULL
| NULL
|
| Perez
| Luis
| Urquiza 444
| 0354545256 | perezluisalberto@hotmail.c
m |
| Lopez
| Maria | Salta 314
| NULL
| lopezmariayo@gmail.com
|
+----------+---------+----------------+------------+----------------------------+
6 rows in set (0.00 sec)
Database changed
mysql> create table visitantes(
-> nombre varchar(30),
-> edad tinyint unsigned,
-> sexo char(1),
-> domicilio varchar(30),
-> ciudad varchar(20),
-> telefono varchar(11),
-> montocompra decimal(6,2) unsigned
-> );
Query OK, 0 rows affected (0.14 sec)
mysql> describe visitantes;
+-------------+-----------------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-------------+-----------------------+------+-----+---------+-------+
| nombre
| varchar(30)
| YES |
| NULL
|
|
| edad
| tinyint(3) unsigned | YES |
| NULL
|
|
| sexo
| char(1)
| YES |
| NULL
|
|
| domicilio | varchar(30)
| YES |
| NULL
|
|
| ciudad
| varchar(20)
| YES |
| NULL
|
|
| telefono
| varchar(11)
| YES |
| NULL
|
|
| montocompra | decimal(6,2) unsigned | YES |
| NULL
|
|
+-------------+-----------------------+------+-----+---------+-------+
7 rows in set (0.06 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,monto
compra) values ('Susana Molina', 28,'f','Colon 123','Cordoba',null,45.50);
Query OK, 1 row affected (0.05 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,mont
ocompra) values ('Marcela Mercado',36,'f','Avellaneda 345','Cordoba','4545454',0
);
Query OK, 1 row affected (0.01 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,mont
ocompra) values ('Alberto Garcia',35,'m','Gral. Paz 123','Alta Gracia','03547123
456',25);
Query OK, 1 row affected (0.00 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,mont
ocompra) values ('Teresa Garcia',33,'f','Gral. Paz 123','Alta Gracia','035471234
56',0);
Query OK, 1 row affected (0.02 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,mont
ocompra) values ('Roberto Perez',45,'m','Urquiza 335','Cordoba','4123456',33.20)
;
Query OK, 1 row affected (0.00 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,mont
ocompra) values ('Marina Torres',22,'f','Colon 222','Villa Dolores','03544112233
',25);
Query OK, 1 row affected (0.00 sec)
mysql> insert into visitantes (nombre,edad, sexo,domicilio,ciudad,telefono,mont
ocompra) values ('Julieta Gomez',24,'f','San Martin 333','Alta Gracia','03547121
212',53.50);
Query OK, 1 row affected (0.00 sec)
+-----------------+
1 row in set (0.00 sec)
mysql> select count(*) from visitantes
-> where sexo='m';
+----------+
| count(*) |
+----------+
|
3 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from visitantes
-> where sexo='f' and
-> edad>25;
+----------+
| count(*) |
+----------+
|
4 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from visitantes
-> where ciudad<>'cordaba';
+----------+
| count(*) |
+----------+
|
10 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from visitantes
-> where montocompra<>0;
+----------+
| count(*) |
+----------+
|
7 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from visitantes
-> where montocompra=0;
+----------+
| count(*) |
+----------+
|
3 |
+----------+
1 row in set (0.00 sec)
+------------------+
|
53.50 |
+------------------+
1 row in set (0.05 sec)
mysql> select min(edad) from visitantes;
+-----------+
| min(edad) |
+-----------+
|
20 |
+-----------+
1 row in set (0.00 sec)
mysql> select avg(edad) from visitantes;
+-----------+
| avg(edad) |
+-----------+
| 33.6000 |
+-----------+
1 row in set (0.00 sec)
mysql> select avg(montocompra) from visitantes;
+------------------+
| avg(montocompra) |
+------------------+
|
24.550000 |
+------------------+
1 row in set (0.00 sec)
mysql>
|
7 | Lopez Carlos | Irigoyen 888
| Cruz del Eje
| Cordoba | NU
LL
|
|
8 | Ramos Betina | San Martin 999 | Cordoba
| Cordoba | 42
23366
|
|
9 | Lopez Lucas
| San Martin 1010 | Posadas
| Misiones | 04
57858745 |
+--------+----------------+-----------------+-------------------+-----------+-----------+
9 rows in set (0.00 sec)
mysql> select provincia, count(*)
-> from clientes
-> group by provincia;
+-----------+----------+
| provincia | count(*) |
+-----------+----------+
| Cordoba |
6 |
| Misiones |
1 |
| Santa Fe |
2 |
+-----------+----------+
3 rows in set (0.00 sec)
mysql> select ciudad, provincia, count(*)
-> from clientes
-> group by ciudad,provincia;
+-------------------+-----------+----------+
| ciudad
| provincia | count(*) |
+-------------------+-----------+----------+
| Cordoba
| Cordoba |
1 |
| Cruz del Eje
| Cordoba |
3 |
| Posadas
| Misiones |
1 |
| Rosario
| Santa Fe |
1 |
| Santa Fe
| Santa Fe |
1 |
| Villa del Rosario | Cordoba |
1 |
| Villa Maria
| Cordoba |
1 |
+-------------------+-----------+----------+
7 rows in set (0.00 sec)
mysql> select ciudad, provincia, count(*)
-> from clientes
-> group by ciudad,provincia
-> having count(*)>1;
+--------------+-----------+----------+
| ciudad
| provincia | count(*) |
+--------------+-----------+----------+
| Cruz del Eje | Cordoba |
3 |
+--------------+-----------+----------+
1 row in set (0.00 sec)
mysql> select ciudad, provincia, count(*)
-> from clientes
-> where telefono is not null
-> group by ciudad,provincia
-> having count(*)>1;
+--------------+-----------+----------+
| ciudad
| provincia | count(*) |
+--------------+-----------+----------+
| Cruz del Eje | Cordoba |
2 |
+--------------+-----------+----------+
1 row in set (0.00 sec)
38 - Alias
mysql> use practica;
Database changed
mysql> create table clientes (
-> codigo int unsigned auto_increment,
-> nombre varchar(30) not null,
-> domicilio varchar(30),
-> ciudad varchar(20),
-> provincia varchar (20),
-> telefono varchar(11),
-> primary key(codigo)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> describe clientes;
+-----------+------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-----------+------------------+------+-----+---------+----------------+
| codigo
| int(10) unsigned | NO | PRI | NULL
| auto_increment |
| nombre
| varchar(30)
| NO |
| NULL
|
|
| domicilio | varchar(30)
| YES |
| NULL
|
|
| ciudad
| varchar(20)
| YES |
| NULL
|
|
| provincia | varchar(20)
| YES |
| NULL
|
|
| telefono | varchar(11)
| YES |
| NULL
|
|
+-----------+------------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,provincia,telefono) values
('Lopez Marcos', 'Colon 111', 'Crdoba','Cordoba','null');
ERROR 1366 (HY000): Incorrect string value: '\xA2rdoba' for column 'ciudad' at r
ow 1
mysql> insert into clientes (nombre,domicilio,ciudad,provincia,telefono) values
('Perez Ana', 'San Martin 222', 'Cruz del Eje','Cordoba','4578585');
Query OK, 1 row affected (0.01 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,provincia,telefono) values
('Garcia Juan', 'Rivadavia 333', 'Villa Maria','Cordoba','4578445');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,provincia,telefono) values
('Perez Luis', 'Sarmiento 444', 'Rosario','Santa Fe',null);
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,provincia,telefono) values
('Pereyra Lucas', 'San Martin 555', 'Cruz del Eje','Cordoba','4253685');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,provincia,telefono) values
('Gomez Ines', 'San Martin 666', 'Santa Fe','Santa Fe','0345252525');
Query OK, 1 row affected (0.00 sec)
|
2 |
+-------+
1 row in set (0.00 sec)
mysql> select provincia, count(distinct ciudad) as 'ciudades'
-> from clientes
-> group by provincia;
+-----------+----------+
| provincia | ciudades |
+-----------+----------+
| Cordoba |
4 |
| Misiones |
1 |
| Santa Fe |
2 |
+-----------+----------+
3 rows in set (0.00 sec)
+-----------+--------+----------------------+---------+-----------+------------+
| 23
| tabasco | reforma
| 2
| amor
| 25
| meridad | tabasco
| 9171025734 |
| 20
| 9931025734 |
| 26
| reforma | agulera
| 9931034534 |
| 27
| reforma | morelos
| 9245034534 |
| 28
| karen | medellin
| tabasco | aoxaca
| 9245034345 |
| 29
| tapia | indeco
| calle vicente
| 9171123457 |
+-----------+--------+----------------------+---------+-----------+------------+
8 rows in set (0.00 sec)
mysql> create index i_ciudadprovincia on clientes (ciudad,provincia);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show index from clientes;
+----------+------------+-------------------+--------------+-------------+----------+-------------+----------+--------+------+------------+---------+--------------+
| Table
| Non_unique | Key_name
| Seq_in_index | Column_name | Colla
tion | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_com
ment |
+----------+------------+-------------------+--------------+-------------+----------+-------------+----------+--------+------+------------+---------+--------------+
| clientes |
1 | i_ciudadprovincia |
1 | ciudad
| A
|
8 |
NULL | NULL | YES | BTREE
|
|
|
| clientes |
1 | i_ciudadprovincia |
2 | provincia | A
|
8 |
NULL | NULL | YES | BTREE
|
|
|
+----------+------------+-------------------+--------------+-------------+----------+-------------+----------+--------+------+------------+---------+--------------+
2 rows in set (0.00 sec)
mysql> create unique index i_documento on clientes(documento);
Query OK, 0 rows affected (0.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select*from clientes;
+-----------+--------+----------------------+---------+-----------+------------+
| documento | nombre | domicilio
+-----------+--------+----------------------+---------+-----------+------------+
| 2
| amor
| calle vicente
| 20
| 9931025734 |
| 23
| tabasco | reforma
| 9171123457 |
| 25
| meridad | tabasco
| 9171025734 |
| 26
| reforma | agulera
| 9931034534 |
| 27
| reforma | morelos
| 9245034534 |
| 28
| karen | medellin
| tabasco | aoxaca
| 9245034345 |
| 29
| tapia | indeco
+-----------+--------+----------------------+---------+-----------+------------+
+--------+------------------------+-------------------+----------+
| codigo | titulo
| actor
| duracion |
+--------+------------------------+-------------------+----------+
|
1 | elgatoraton
| tom cruise
|
90 |
|
2 | mision imposible
| tom cruise
|
90 |
|
4 | Harry Potter
| Daniel R
|
120 |
|
5 | mision imposible3
| tom cruise
|
92 |
|
6 | mujer bonita
| julia R
|
90 |
|
7 | mujer bonita2
| julia R
|
90 |
|
8 | el mostro de lago nees | martin trijillo |
120 |
|
9 | contrabando y arma
| catinfla
|
90 |
|
10 | el futbolista
| resorte resortera |
90 |
+--------+------------------------+-------------------+----------+
9 rows in set (0.00 sec)
|
7 | mujer bonita2
| julia R
|
90 |
|
8 | el mostro de lago nees | martin trijillo |
120 |
|
9 | contrabando y arma
| catinfla
|
90 |
|
10 | el futbolista
| resorte resortera |
90 |
+--------+------------------------+-------------------+----------+
5 rows in set (0.00 sec)
mysql> select*from peliculas limit 2,10;
+--------+------------------------+-------------------+----------+
| codigo | titulo
| actor
| duracion |
+--------+------------------------+-------------------+----------+
|
4 | Harry Potter
| Daniel R
|
120 |
|
5 | mision imposible3
| tom cruise
|
92 |
|
6 | mujer bonita
| julia R
|
90 |
|
7 | mujer bonita2
| julia R
|
90 |
|
8 | el mostro de lago nees | martin trijillo |
120 |
|
9 | contrabando y arma
| catinfla
|
90 |
|
10 | el futbolista
| resorte resortera |
90 |
+--------+------------------------+-------------------+----------+
7 rows in set (0.00 sec)
mysql> select*from peliculas order by codigo desc limit 0,5;
+--------+------------------------+-------------------+----------+
| codigo | titulo
| actor
| duracion |
+--------+------------------------+-------------------+----------+
|
10 | el futbolista
| resorte resortera |
90 |
|
9 | contrabando y arma
| catinfla
|
90 |
|
8 | el mostro de lago nees | martin trijillo |
120 |
|
7 | mujer bonita2
| julia R
|
90 |
|
6 | mujer bonita
| julia R
|
90 |
+--------+------------------------+-------------------+----------+
5 rows in set (0.00 sec)
mysql> select*from peliculas order by codigo desc limit 5,10;
+--------+-------------------+------------+----------+
| codigo | titulo
| actor
| duracion |
+--------+-------------------+------------+----------+
|
5 | mision imposible3 | tom cruise |
92 |
|
4 | Harry Potter
| Daniel R |
120 |
|
2 | mision imposible | tom cruise |
90 |
|
1 | elgatoraton
| tom cruise |
90 |
+--------+-------------------+------------+----------+
4 rows in set (0.00 sec)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe alumnos;
+------------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| documentos | char(8)
| NO | PRI | NULL
|
|
| nombre
| varchar(30) | YES |
| NULL
|
|
| domicilio | varchar(30) | YES |
| NULL
|
|
| ciudad
| varchar(20) | YES |
| NULL
|
|
| provincia | varchar(20) | YES |
| NULL
|
|
+------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> insert into alumnos values('22333444','Juan Perez','Colon 123','Cordoba',
'Cordoba');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('23456789','Ana Acosta','Caseros 456','Cordob
a','Cordoba');
Query OK, 1 row affected (0.01 sec)
mysql> insert into alumnos values('24123123','Patricia Morales','Sucre 234','Vi
lla del Rosario','Cordoba');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('25000333','Jose Torres','Sarmiento 980','Car
los Paz','Cordoba');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('26333444','Susana Molina','Avellaneda 234','
Rosario','Santa Fe');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('27987654','Marta Herrero','San Martin 356','
Villa del Rosario','Cordoba');
Query OK, 1 row affected (0.02 sec)
mysql> insert into alumnos values('28321321','Marcos Ferreyra','Urquiza 357','C
ordoba','Cordoba');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('30987464','Marta Perez','Rivadavia 234','Cor
doba','Cordoba');
Query OK, 1 row affected (0.01 sec)
mysql> select*from alumnos;
+------------+------------------+----------------+-------------------+----------+
| documentos | nombre
| domicilio
| ciudad
| provincia
|
+------------+------------------+----------------+-------------------+----------+
| 22333444 | Juan Perez
| Colon 123
| Cordoba
| Cordoba
|
| 23456789 | Ana Acosta
| Caseros 456
| Cordoba
| Cordoba
|
| 24123123 | Patricia Morales | Sucre 234
| Villa del Rosario | Cordoba
|
| direccion | varchar(20)
| YES |
| NULL
|
|
+-----------+---------------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
mysql> alter table peliculas add actor varchar(20);
ERROR 1060 (42S21): Duplicate column name 'actor'
mysql>
0 | PRIMARY
NULL | NULL |
1 | codigo
|
|
| A
| BTREE
|
|
| peliculas |
3 |
1 | i_director |
NULL | NULL | YES | BTREE
1 | director
|
|
| A
|
|
+-----------+------------+------------+--------------+-------------+-----------+
-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.01 sec)
mysql> alter table peliculas
-> drop director;
Query OK, 3 rows affected (0.11 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> describe peliculas;
+-----------------+---------------------+------+-----+---------+---------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-----------------+---------------------+------+-----+---------+---------------+
| codigo
| int(10) unsigned
| NO | PRI | NULL
| auto_increment
|
| nombre
| varchar(30)
| NO |
| NULL
|
|
| protagonista
| varchar(20)
| YES |
| NULL
|
|
| actorsecundario | varchar(20)
| YES |
| NULL
|
|
| duracion
| tinyint(3) unsigned | YES |
| NULL
|
|
+-----------------+---------------------+------+-----+---------+---------------+
5 rows in set (0.01 sec)
mysql> show index from peliculas;
+-----------+------------+----------+--------------+-------------+-----------+------------+----------+--------+------+------------+---------+---------------+
| Table
| Non_unique | Key_name | Seq_in_index | Column_name | Collation | C
ardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+----------+--------------+-------------+-----------+------------+----------+--------+------+------------+---------+---------------+
| peliculas |
0 | PRIMARY |
1 | codigo
| A
|
3 |
NULL | NULL |
| BTREE
|
|
|
+-----------+------------+----------+--------------+-------------+-----------+------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe articulos;
+-------------+-----------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-------------+-----------------------+------+-----+---------+----------------+
| codigo
| int(10) unsigned
| NO | PRI | NULL
| auto_increment |
| nombre
| varchar(20)
| NO |
| NULL
|
|
| descripcion | varchar(30)
| YES |
| NULL
|
|
| precio
| decimal(4,2) unsigned | YES |
| NULL
|
|
+-------------+-----------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> insert into articulos (nombre,descripcion,precio) values('escuadra','pla
stico 20 cm.',3.50);
Query OK, 1 row affected (0.00 sec)
mysql> insert into articulos (nombre,descripcion,precio)
es','Faber x12',4.50);
ERROR 1366 (HY000): Incorrect string value: '\xA0pices...'
t row 1
mysql> insert into articulos (nombre,descripcion,precio)
es','Faber x24',7.50);
ERROR 1366 (HY000): Incorrect string value: '\xA0pices...'
t row 1
mysql> insert into articulos (nombre,descripcion,precio)
.',2.50);
Query OK, 1 row affected (0.00 sec)
values('lpices color
for column 'nombre' a
values('lpices color
for column 'nombre' a
values('regla','30 cm
|
3 | fibras | Faber x12
|
10.30 |
|
4 | fibras | Faber x6
|
5.10 |
+--------+----------+-----------------+---------------+
4 rows in set (0.00 sec)
mysql> alter table articulos
-> add preciopormenor decimal(4,2) unsigned not null;
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select*from articulos;
+--------+----------+-----------------+---------------+----------------+
| codigo | nombre | descripcion
| preciopormayo | preciopormenor |
+--------+----------+-----------------+---------------+----------------+
|
1 | escuadra | plastico 20 cm. |
3.50 |
0.00 |
|
2 | regla
| 30 cm.
|
2.50 |
0.00 |
|
3 | fibras | Faber x12
|
10.30 |
0.00 |
|
4 | fibras | Faber x6
|
5.10 |
0.00 |
+--------+----------+-----------------+---------------+----------------+
4 rows in set (0.00 sec)
mysql> select*from articulos;
+--------+----------+-----------------+---------------+----------------+
| codigo | nombre | descripcion
| preciopormayo | preciopormenor |
+--------+----------+-----------------+---------------+----------------+
|
1 | escuadra | plastico 20 cm. |
3.50 |
0.00 |
|
2 | regla
| 30 cm.
|
2.50 |
0.00 |
|
3 | fibras | Faber x12
|
10.30 |
0.00 |
|
4 | fibras | Faber x6
|
5.10 |
0.00 |
+--------+----------+-----------------+---------------+----------------+
4 rows in set (0.00 sec)
| libros
|
| medicamentos
|
| pedido
|
| peliculas
|
| prestamos
|
| visitantes
|
+--------------------+
14 rows in set (0.00 sec)
mysql> drop table alumnos;
Query OK, 0 rows affected (0.06 sec)
mysql> use practica;
Database changed
mysql> create table alumnos(
-> legajo int unsigned auto_increment,
-> nombre varchar(30),
-> documentos char(8)not null,
-> domiclio varchar(30),
-> ciudad varchar(20),
-> provincia varchar(20),
-> primary key(legajo)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe alumnos;
+------------+------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+------------+------------------+------+-----+---------+----------------+
| legajo
| int(10) unsigned | NO | PRI | NULL
| auto_increment |
| nombre
| varchar(30)
| YES |
| NULL
|
|
| documentos | char(8)
| NO |
| NULL
|
|
| domiclio | varchar(30)
| YES |
| NULL
|
|
| ciudad
| varchar(20)
| YES |
| NULL
|
|
| provincia | varchar(20)
| YES |
| NULL
|
|
+------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)
mysql> alter table alumnos
-> add index i_ciudadprovincia(ciudad,provincia);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table alumnos
-> add uniqueindex i_documentos (documentos);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'i_doc
umentos (documentos)' at line 2
mysql> show index from alumnos;
+---------+------------+-------------------+--------------+-------------+----------+-------------+----------+--------+------+------------+---------+--------------+
| Table | Non_unique | Key_name
| Seq_in_index | Column_name | Collat
ion | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comm
ent |
+---------+------------+-------------------+--------------+-------------+----------+-------------+----------+--------+------+------------+---------+--------------+
| alumnos |
0 | PRIMARY
|
1 | legajo
| A
|
0 |
NULL | NULL |
| BTREE
|
|
|
| alumnos |
1 | i_ciudadprovincia |
1 | ciudad
| A
|
0 |
NULL | NULL | YES | BTREE
|
|
|
| alumnos |
1 | i_ciudadprovincia |
2 | provincia | A
|
0 |
NULL | NULL | YES | BTREE
|
|
|
+---------+------------+-------------------+--------------+-------------+----------+-------------+----------+--------+------+------------+---------+--------------+
3 rows in set (0.00 sec)
| Field
| Type
|
Null | Key | Default | Extra
|
+-------------+---------------------------------------------------------------+-----+-----+---------+----------------+
| codigo
| tinyint(3) unsigned
|
NO | PRI | NULL
| auto_increment |
| tema
| varchar(20)
|
NO |
| NULL
|
|
| dias
| set('lunes','martes','miercoles','jueves','viernes','sabado') |
NO |
| NULL
|
|
| horario
| enum('AM','PM')
|
NO |
| NULL
|
|
| clases
| tinyint(3) unsigned
|
YES |
| 1
|
|
| fechainicio | date
|
YES |
| NULL
|
|
| costo
| decimal(5,2) unsigned
|
YES |
| NULL
|
|
+-------------+---------------------------------------------------------------+-----+-----+---------+----------------+
7 rows in set (0.01 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('PH
P basico','lunes,martes,miercoles','AM',18,'2006-08-07',200);
Query OK, 1 row affected (0.03 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('PH
P basico','lunes,martes,miercoles','PM',18,'2006-08-14',200);
Query OK, 1 row affected (0.00 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('PH
P basico','sabado','AM',18,'2006-08-05',280);
Query OK, 1 row affected (0.00 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('PH
P avanzado','martes,jueves','AM',20,'2006-08-01',350);
Query OK, 1 row affected (0.00 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('ja
vascript','lunes,martes,miercoles,','PM',15,'2006-09-11',150);
ERROR 1265 (01000): Data truncated for column 'dias' at row 1
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('ja
va script','lunes,martes,miercoles','PM',15,'2006-09-11',150);
Query OK, 1 row affected (0.01 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('pa
gina web','martes,jueves','PM',10,'2006-08-08',250);
Query OK, 1 row affected (0.02 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('pa
gina web','sabado','AM',10,'2006-08-12',280);
Query OK, 1 row affected (0.00 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('pa
gina web','lunes,viernes','AM',10,'2006-08-21',200);
Query OK, 1 row affected (0.00 sec)
mysql> insert into cursos(tema,dias,horario,clases,fechainicio,costo) values('pa
gina web','lunes,martes,miercoles,jueves,viernes','AM',10,'2006-09-18',180);
Query OK, 1 row affected (0.00 sec)
| 2756 |
4.80 | regular
|
| 4856 |
3.20 | reprobado
|
| 7856 |
6.40 | regular
|
+--------+----------+--------------+
5 rows in set (0.04 sec)
mysql> select legajo,promedio,
-> case when promedio<4 then 'reprobado'
-> when promedio<4 and promedio<7 then 'regular'
-> else 'promocionado'
-> end as 'estado'
-> from alumnos;
+--------+----------+--------------+
| legajo | promedio | estado
|
+--------+----------+--------------+
| 3456 |
8.50 | promocionado |
| 3556 |
7.00 | promocionado |
| 2756 |
4.80 | promocionado |
| 4856 |
3.20 | reprobado
|
| 7856 |
6.40 | promocionado |
+--------+----------+--------------+
5 rows in set (0.00 sec)
| domicilio
| ciudad
| nombre
| telefono
+----------------+-----------------+-------------------+----------+------------+
| lopez marcos
| colon 111
| perez ana
| cordoba
| Cordoba | null
| Cordoba | 4578585
| Garcia Juan
| Rivadavia 333
| Villa Maria
| Cordoba | 4578445
| Perez Luis
| Sarmiento 444
| Rosario
| Santa Fe | NULL
| Cordoba | 4253685
| Gomez Ines
| Santa Fe | 0345252525 |
| Lopez Carlos
| Irigoyen 888
| Cordoba | NULL
| Ramos Betina
| Cordoba | 4223366
| Lopez Lucas
| Misiones | 0457858745 |
+----------------+-----------------+-------------------+----------+------------+
10 rows in set (0.00 sec)
mysql>
->
->
->
select c.nombre,c.domicilio,c.ciudad,p.nombre,c.telefono
from clientes as c
join provincias as p
on c.codigoprovincia=p.codigo;
+----------------+-----------------+-------------------+----------+------------+
| nombre
| domicilio
| ciudad
| nombre
| telefono
+----------------+-----------------+-------------------+----------+------------+
| lopez marcos
| colon 111
| perez ana
| cordoba
| Cordoba | null
| Cordoba | 4578585
| Garcia Juan
| Rivadavia 333
| Villa Maria
| Cordoba | 4578445
| Perez Luis
| Sarmiento 444
| Rosario
| Santa Fe | NULL
| Cordoba | 4253685
| Gomez Ines
| Santa Fe | 0345252525 |
| Lopez Carlos
| Irigoyen 888
| Cordoba | NULL
| Ramos Betina
| Cordoba | 4223366
| Lopez Lucas
| Misiones | 0457858745 |
+----------------+-----------------+-------------------+----------+------------+
10 rows in set (0.00 sec)
mysql> select c.nombre,c.domicilio,c.ciudad,p.nombre,c.telefono
-> from clientes as c
-> join provincias as p
-> on c.codigoprovincia=p.codigo
-> order by c.nombre;
+----------------+-----------------+-------------------+----------+------------+
| nombre
| domicilio
| ciudad
| nombre
| telefono
+----------------+-----------------+-------------------+----------+------------+
| Garcia Juan
| Rivadavia 333
| Gomez Ines
| Santa Fe | 0345252525 |
| Lopez Carlos
| Irigoyen 888
| Cordoba | NULL
| Lopez Lucas
| Misiones | 0457858745 |
| lopez marcos
| colon 111
| Cordoba | null
| Cordoba | 4253685
| perez ana
| Cordoba | 4578585
| Perez Luis
| Sarmiento 444
| Santa Fe | NULL
| Ramos Betina
| Cordoba | 4223366
| Villa Maria
| cordoba
| Rosario
| Cordoba | 4578445
+----------------+-----------------+-------------------+----------+------------+
10 rows in set (0.03 sec)
mysql>
->
->
->
select c.nombre,c.domicilio,c.ciudad,p.nombre,c.telefono
from clientes as c
join provincias as p
on codigoprovincia=codigo
63 - Clave fornea.
mysql> use practica;
Database changed
mysql> create table clientes (
-> codigo int unsigned auto_increment,
-> nombre varchar(30) not null,
-> domicilio varchar(30),
-> ciudad varchar(20),
-> codigoprovincia tinyint unsigned,
-> telefono varchar(11),
-> primary key(codigo)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> create table provincias(
-> codigo tinyint unsigned auto_increment,
-> nombre varchar(20),
-> primary key (codigo)
-> );
Query OK, 0 rows affected (0.36 sec)
mysql> describe provincias;
+--------+---------------------+------+-----+---------+----------------+
| Field | Type
| Null | Key | Default | Extra
|
+--------+---------------------+------+-----+---------+----------------+
| codigo | tinyint(3) unsigned | NO | PRI | NULL
| auto_increment |
| nombre | varchar(20)
| YES |
| NULL
|
|
+--------+---------------------+------+-----+---------+----------------+
2 rows in set (0.02 sec)
mysql> insert into provincias(codigo,nombre) values(1,'Cordoba');
Query OK, 1 row affected (0.00 sec)
mysql> insert into provincias(codigo,nombre) values(2,'Santa Fe');
Query OK, 1 row affected (0.00 sec)
mysql> insert into provincias(codigo,nombre) values(30,'Misiones');
Query OK, 1 row affected (0.00 sec)
mysql> insert into provincias(codigo,nombre) values(13,'Salta');
Query OK, 1 row affected (0.00 sec)
mysql> insert into provincias(codigo,nombre) values(15,'Buenos Aires');
Query OK, 1 row affected (0.00 sec)
+-----------------+---------------------+------+-----+---------+---------------+
6 rows in set (0.01 sec)
mysql>
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
values ('Lopez Marcos', 'Colon 111', 'Crdoba',1,'null');
ERROR 1366 (HY000): Incorrect string value: '\xA2rdoba' for column 'ciudad' at r
ow 1
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Perez Ana', 'San Martin 222', 'Cruz del Eje',1,'4578585');
Query OK, 1 row affected (0.02 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Garcia Juan', 'Rivadavia 333', 'Villa Maria',1,'4578445');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Perez Luis', 'Sarmiento 444', 'Rosario',2,null);
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Pereyra Lucas', 'San Martin 555', 'Cruz del Eje',1,'4253685');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Gomez Ines', 'San Martin 666', 'Santa Fe',2,'0345252525');
Query OK, 1 row affected (0.02 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Torres Fabiola', 'Alem 777', 'Villa del Rosario',1,'4554455');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Lopez Carlos', 'Irigoyen 888', 'Cruz del Eje',1,null);
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Ramos Betina', 'San Martin 999', 'Cordoba',1,'4223366');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Lopez Lucas', 'San Martin 1010', 'Posadas',4,'0457858745');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Lopez Marcos', 'Colon 111', 'Crdoba',1,'null');
ERROR 1366 (HY000): Incorrect string value: '\xA2rdoba' for column 'ciudad' at r
ow 1
mysql> select p.codigo,p.nombre from provincias as p
-> left join clientes as c
-> on c.codigoProvincia=p.codigo
-> where c.codigoprovincia is null;
+--------+--------------+
| codigo | nombre
|
+--------+--------------+
|
3 | Corrientes |
|
5 | Salta
|
|
6 | Buenos Aires |
|
7 | Neuquen
|
+--------+--------------+
4 rows in set (0.00 sec)
mysql> select distinct p.codigo,p.nombre from provincias as p
-> left join clientes as c
-> on c.codigoProvincia=p.codigo
-> where c.codigoprovincia is not null;
+--------+----------+
| codigo | nombre |
+--------+----------+
|
1 | Cordoba |
|
2 | Santa Fe |
|
4 | Misiones |
+--------+----------+
3 rows in set (0.00 sec)
mysql> select distinct codigo,p.nombre from provincias as p
-> left join clientes as c
-> on c.codigoProvincia=p.codigo
-> where c.codigoprovincia is not null;
ERROR 1052 (23000): Column 'codigo' in field list is ambiguous
mysql>
| documento | char(8)
| NO | PRI | NULL
|
|
| deporte | varchar(15) | NO | PRI | NULL
|
|
| anio
| year(4)
| NO | PRI | 0000
|
|
| matricula | char(1)
| YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
mysql> insert into inscriptos values ('22333444','natacion','2005','s');
Query OK, 1 row affected (0.02 sec)
mysql> insert into inscriptos values ('22333444','natacion','2006','n');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values ('23333444','natacion','2005','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values ('23333444','tenis','2006','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values ('23333444','natacion','2006','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values ('24333444','tenis','2006','n');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values ('24333444','basquet','2006','n');
Query OK, 1 row affected (0.00 sec)
mysql> select nombre,i.*
-> from socios as s
-> natural join inscriptos as i;
+----------------+-----------+----------+------+-----------+
| nombre
| documento | deporte | anio | matricula |
+----------------+-----------+----------+------+-----------+
| Juan Perez
| 22333444 | natacion | 2005 | s
|
| Juan Perez
| 22333444 | natacion | 2006 | n
|
| Maria Lopez
| 23333444 | natacion | 2005 | s
|
| Maria Lopez
| 23333444 | natacion | 2006 | s
|
| Maria Lopez
| 23333444 | tenis
| 2006 | s
|
| Antonio Juarez | 24333444 | basquet | 2006 | n
|
| Antonio Juarez | 24333444 | tenis
| 2006 | n
|
+----------------+-----------+----------+------+-----------+
7 rows in set (0.00 sec)
mysql> select nombre,i.*
-> from socios as s
-> join inscriptos as i
-> on s.documento=i.documento;
+----------------+-----------+----------+------+-----------+
| nombre
| documento | deporte | anio | matricula |
+----------------+-----------+----------+------+-----------+
| Juan Perez
| 22333444 | natacion | 2005 | s
|
| Juan Perez
| 22333444 | natacion | 2006 | n
|
| Maria Lopez
| 23333444 | natacion | 2005 | s
|
| Maria Lopez
| 23333444 | natacion | 2006 | s
|
| Maria Lopez
| 23333444 | tenis
| 2006 | s
|
| Antonio Juarez | 24333444 | basquet | 2006 | n
|
| Antonio Juarez | 24333444 | tenis
| 2006 | n
|
+----------------+-----------+----------+------+-----------+
7 rows in set (0.00 sec)
values('Misiones');
+
| codigo
| int(10) unsigned
| NO | PRI | NULL
| auto_increment
|
| nombre
| varchar(30)
| NO |
| NULL
|
|
| domicilio
| varchar(30)
| YES |
| NULL
|
|
| ciudad
| varchar(20)
| YES |
| NULL
|
|
| codigoprovincia | tinyint(3) unsigned | YES |
| NULL
|
|
| telefono
| varchar(11)
| YES |
| NULL
|
|
+-----------------+---------------------+------+-----+---------+---------------+
6 rows in set (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Lopez Marcos', 'Colon 111', 'Crdoba',1,'null');
ERROR 1366 (HY000): Incorrect string value: '\xA2rdoba' for column 'ciudad' at r
ow 1
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Perez Ana', 'San Martin 222', 'Cruz del Eje',1,'4578585');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Garcia Juan', 'Rivadavia 333', 'Villa Maria',1,'4578445');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Perez Luis', 'Sarmiento 444', 'Rosario',2,null);
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Pereyra Lucas', 'San Martin 555', 'Cruz del Eje',1,'4253685');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Gomez Ines', 'San Martin 666', 'Santa Fe',2,'0345252525');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Torres Fabiola', 'Alem 777', 'Villa del Rosario',1,'4554455');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Lopez Carlos', 'Irigoyen 888', 'Cruz del Eje',1,null);
Query OK, 1 row affected (0.02 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Ramos Betina', 'San Martin 999', 'Cordoba',1,'4223366');
Query OK, 1 row affected (0.00 sec)
mysql> insert into clientes (nombre,domicilio,ciudad,codigoProvincia,telefono)
-> values ('Lopez Lucas', 'San Martin 1010', 'Posadas',4,'0457858745');
Query OK, 1 row affected (0.01 sec)
mysql> select p.nombre,
ERROR 1406 (22001): Data too long for column 'titulo' at row 1
mysql> describe socios;
+-----------+----------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-----------+----------------------+------+-----+---------+----------------+
| codigo
| smallint(5) unsigned | NO | PRI | NULL
| auto_increment |
| documento | char(8)
| YES |
| NULL
|
|
| nombre
| varchar(30)
| YES |
| NULL
|
|
| domicilio | varchar(30)
| YES |
| NULL
|
|
+-----------+----------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> insert into socios (documento,nombre)
-> values('22333444','Juan Lopez');
Query OK, 1 row affected (0.00 sec)
mysql> insert into socios (documento,nombre)
-> values('23333444','Diana Perez');
Query OK, 1 row affected (0.00 sec)
mysql> insert into socios (documento,nombre)
-> values('24333444','Luis Fuentes');
Query OK, 1 row affected (0.03 sec)
mysql> describe alquileres;
+-----------------+----------------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------------+----------------------+------+-----+---------+-------+
| codigopelicula | smallint(5) unsigned | NO | PRI | NULL
|
|
| codigosocio
| smallint(5) unsigned | NO |
| NULL
|
|
| fechaprestamo | date
| NO | PRI | NULL
|
|
| fechadevolucion | date
| YES |
| NULL
|
|
+-----------------+----------------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(1,1,'2006-07-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(2,1,'2006-07-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(3,1,'2006-07-12');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(1,2,'2006-08-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(3,2,'2006-08-12');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(4,2,'2006-08-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(1,3,'2006-09-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(2,3,'2006-08-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(3,3,'2006-08-15');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(4,3,'2006-08-22');
Query OK, 1 row affected (0.03 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(4,1,'2006-08-25');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alquileres (codigopelicula,codigosocio,fechaprestamo)
-> values(1,3,'2006-08-25');
Query OK, 1 row affected (0.00 sec)
mysql> select titulo,nombre,fechaprestamo,fechadevolucion from alquileres as a
-> join peliculas as p
-> on a.codigopelicula=p.codigo
-> join socios as s
-> on s.codigo=a.codigosocio;
+--------------------+--------------+---------------+-----------------+
| titulo
| nombre
| fechaprestamo | fechadevolucion |
+--------------------+--------------+---------------+-----------------+
| Elsa y Fred
| Juan Lopez | 2006-07-02
| NULL
|
| Mision imposible | Juan Lopez | 2006-07-02
| NULL
|
| Mision imposible 2 | Juan Lopez | 2006-07-12
| NULL
|
| Elsa y Fred
| Diana Perez | 2006-08-02
| NULL
|
| Mision imposible 2 | Diana Perez | 2006-08-12
| NULL
|
| Elsa y Fred
| Luis Fuentes | 2006-08-25
| NULL
|
| Elsa y Fred
| Luis Fuentes | 2006-09-02
| NULL
|
| Mision imposible | Luis Fuentes | 2006-08-02
| NULL
|
| Mision imposible 2 | Luis Fuentes | 2006-08-15
| NULL
|
+--------------------+--------------+---------------+-----------------+
9 rows in set (0.00 sec)
mysql> select p.titulo,count(*) from peliculas as p
-> join alquileres as a
-> on p.codigo=a.codigopelicula
-> group by p.titulo;
+--------------------+----------+
| titulo
| count(*) |
+--------------------+----------+
| Elsa y Fred
|
4 |
| Mision imposible |
2 |
| Mision imposible 2 |
3 |
+--------------------+----------+
3 rows in set (0.00 sec)
mysql> select s.nombre,count(a.codigopelicula) from socios as s
-> join alquileres as a
-> on s.codigo=a.codigosocio
-> group by s.nombre;
+--------------+-------------------------+
| nombre
| count(a.codigopelicula) |
+--------------+-------------------------+
| Diana Perez |
3 |
| Juan Lopez |
4 |
| Luis Fuentes |
5 |
+--------------+-------------------------+
3 rows in set (0.00 sec)
mysql> select s.nombre,count(distinct a.codigopelicula) from socios as s
-> join alquileres as a
-> on s.codigo=a.codigosocio
-> group by s.nombre;
+--------------+----------------------------------+
| nombre
| count(distinct a.codigopelicula) |
+--------------+----------------------------------+
| Diana Perez |
3 |
| Juan Lopez |
4 |
| Luis Fuentes |
4 |
+--------------+----------------------------------+
3 rows in set (0.00 sec)
mysql> select s.nombre,
-> monthname(a.fechaprestamo) as mes,
-> count(a.codigopelicula)
-> from socios as s
-> join alquileres as a
-> on s.codigo=a.codigosocio
-> group by s.nombre, mes
-> order by mes;
+--------------+-----------+-------------------------+
| nombre
| mes
| count(a.codigopelicula) |
+--------------+-----------+-------------------------+
| Luis Fuentes | August
|
4 |
| Juan Lopez | August
|
1 |
| Diana Perez | August
|
3 |
| Juan Lopez | July
|
3 |
| Luis Fuentes | September |
1 |
+--------------+-----------+-------------------------+
5 rows in set (0.05 sec)
mysql>
| alquileres
|
| alumnos
|
| articulos
|
| autos
|
| cuenta
|
| cursos
|
| empleados
|
| guardias
|
| inmueble
|
| inscriptos
|
| libros
|
| medicamentos
|
| pedido
|
| peliculas
|
| prestamos
|
| provincias
|
| socios
|
| tareas
|
| visitantes
|
+--------------------+
20 rows in set (0.00 sec)
mysql> drop tables alumnos;
Query OK, 0 rows affected (0.06 sec)
mysql> use practica;
Database changed
mysql> create table alumnos(
-> documento char(8) not null,
-> nombre varchar(30),
-> primary key(documento)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> create table notas(
-> documento char(8) not null,
-> nota decimal(4,2) unsigned
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> describe alumnos;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| documento | char(8)
| NO | PRI | NULL
|
|
| nombre
| varchar(30) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> insert into alumnos values('22333444','Juan Perez');
Query OK, 1 row affected (0.02 sec)
mysql> insert into alumnos values('23555666','Marina Herrero');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('24000333','Daniel Juarez');
Query OK, 1 row affected (0.00 sec)
mysql> insert into alumnos values('25222111','Hector Paz');
72 - Variables de usuario.
mysql> use practica;
Database changed
mysql> drop table peliculas;
Query OK, 0 rows affected (0.00 sec)
mysql> use practica;
Database changed
mysql> create table peliculas (
-> codigo smallint unsigned auto_increment,
-> titulo varchar(30) not null,
-> actor varchar(30),
-> duracion tinyint unsigned,
-> primary key (codigo)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe peliculas;
+----------+----------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+----------+----------------------+------+-----+---------+----------------+
| codigo | smallint(5) unsigned | NO | PRI | NULL
| auto_increment |
| titulo | varchar(30)
| NO |
| NULL
|
|
| actor
| varchar(30)
| YES |
| NULL
|
|
| duracion | tinyint(3) unsigned | YES |
| NULL
|
|
+----------+----------------------+------+-----+---------+----------------+
4 rows in set (0.02 sec)
mysql> insert into peliculas (titulo,actor,duracion)
-> values('Elsa y Fred','China Zorrilla',90);
Query OK, 1 row affected (0.00 sec)
mysql> insert into peliculas (titulo,actor,duracion)
-> values('Mision imposible','Tom Cruise',120);
Query OK, 1 row affected (0.00 sec)
mysql> insert into peliculas (titulo,actor,duracion)
-> values('Mision imposible 2','Tom Cruise',180);
Query OK, 1 row affected (0.00 sec)
mysql> insert into peliculas (titulo,actor,duracion)
-> values('Harry Potter y la piedra filosofal','Daniel H.',120);
ERROR 1406 (22001): Data too long for column 'titulo' at row 1
mysql> insert into peliculas (titulo,actor,duracion)
-> values('Harry Potter y la camara secreta','Daniel H.',150);
ERROR 1406 (22001): Data too long for column 'titulo' at row 1
mysql> select @mayorduracion:=max(duracion), @menorduracion:= min(duracion) from
peliculas;
+-------------------------------+--------------------------------+
| @mayorduracion:=max(duracion) | @menorduracion:= min(duracion) |
+-------------------------------+--------------------------------+
|
180 |
90 |
+-------------------------------+--------------------------------+
1 row in set (0.00 sec)
mysql> select * from peliculas
-> where duracion=@mayorduracion or
-> duracion=@menorduracion;
+--------+--------------------+----------------+----------+
| codigo | titulo
| actor
| duracion |
+--------+--------------------+----------------+----------+
|
1 | Elsa y Fred
| China Zorrilla |
90 |
|
3 | Mision imposible 2 | Tom Cruise
|
180 |
+--------+--------------------+----------------+----------+
2 rows in set (0.00 sec)
mysql> select @actor:=actor
| cuota
| char(1)
| YES |
| NULL
|
|
+-------------+------------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
mysql> insert into inscriptos values(23,'tenis','2005','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values(23,'tenis','2006','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values(23,'natacion','2005','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values(102,'tenis','2005','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos values(102,'natacion','2006','s');
Query OK, 1 row affected (0.00 sec)
mysql> insert into inscriptos (numerosocio,deporte,ao,cuota)
-> select numero,'tenis','2006','s'
-> from socios
-> where documento='23333444';
ERROR 1300 (HY000): Invalid utf8 character string: 'a\xA4o'
mysql> insert into inscriptos (numerosocio,deporte,anio,cuota)
-> select numero,'tenis','2006','s'
-> from socios
-> where documento='23333444';
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select numero,'tenis','2006','s'
-> from socios
-> where documento='30333444';
Empty set (0.00 sec)
mysql> select numero,'basquet','2006','n'
-> from socios
-> where nombre='Agustin Perez' and
-> domicilio='Urquiza 283';
+--------+---------+------+---+
| numero | basquet | 2006 | n |
+--------+---------+------+---+
|
231 | basquet | 2006 | n |
+--------+---------+------+---+
1 row in set (0.00 sec)
mysql> insert into inscriptos (numerosocio,deporte,ao,cuota)
-> select numero,'natacion','2006','n'
-> from socios
-> where domicilio='Urquiza 283';
ERROR 1300 (HY000): Invalid utf8 character string: 'a\xA4o'
mysql> select numero,'natacion','2006','n'
-> from socios
-> where domicilio='Urquiza 283';
+--------+----------+------+---+
| numero | natacion | 2006 | n |
+--------+----------+------+---+
|
230 | natacion | 2006 | n |
|
231 | natacion | 2006 | n |
+--------+----------+------+---+
2 rows in set (0.00 sec)
mysql> select s.nombre,i.deporte,i.ao
-> from socios as s
-> join inscriptos as i
-> on s.numero=i.numerosocio;
ERROR 1300 (HY000): Invalid utf8 character string: 'a\xA4o'
mysql> select s.nombre,i.deporte,i.anio
-> from socios as s
-> join inscriptos as i
-> on s.numero=i.numerosocio;
+----------------+----------+------+
| nombre
| deporte | anio |
+----------------+----------+------+
| Juan Perez
| natacion | 2005 |
| Juan Perez
| tenis
| 2005 |
| Juan Perez
| tenis
| 2006 |
| Ana Garcia
| tenis
| 2006 |
| Hector Fuentes | natacion | 2006 |
| Hector Fuentes | tenis
| 2005 |
+----------------+----------+------+
6 rows in set (0.00 sec)
mysql>
| descripcion
| varchar(30)
| YES |
| NULL
|
|
| precioporunidad | decimal(5,2) unsigned
| YES |
| NULL
|
|
| cantidad
| tinyint(3) unsigned
| YES |
| NULL
|
|
+-----------------+---------------------------+------+-----+---------+---------------+
5 rows in set (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(100,1,'escuadra 20 cm.',2.50,20);
Query OK, 1 row affected (0.02 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(100,2,'escuadra 50 cm.',5,30);
Query OK, 1 row affected (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(100,3,'goma lapiz-tinta',0.35,100);
Query OK, 1 row affected (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(102,1,'lapices coloresx6',4.40,50);
Query OK, 1 row affected (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(102,2,'lapices coloresx12',8,60);
Query OK, 1 row affected (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(255,1,'lapices coloresx24',12.35,100);
Query OK, 1 row affected (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(567,1,'compas plastico',12,50);
Query OK, 1 row affected (0.00 sec)
mysql> insert into facturas (numero,numeroitem,descripcion,precioporunidad,cant
idad)
-> values(567,2,'compas metal',18.90,80);
Query OK, 1 row affected (0.05 sec)
mysql> create table montofacturas(
-> numero int(10) zerofill,
-> total decimal(9,2) unsigned,
-> primary key(numero)
-> );
ERROR 1050 (42S01): Table 'montofacturas' already exists
mysql> drop table mantofacturas;
ERROR 1051 (42S02): Unknown table 'mantofacturas'
mysql> drop table montofacturas;
Query OK, 0 rows affected (0.01 sec)