EJERCICIO NUMERO 1:
mysql> create database materia_prima;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| materia_prima |
| mysql |
| phpmyadmin |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use materia_prima;
Database changed
mysql> create table productos(codigo varchar(3), nombre varchar(20),precio integ
er(10),fechaalta date);
Query OK, 0 rows affected (0.03 sec)
mysql> insert into productos value("a01","vinos","250","2009/11/02");
Query OK, 1 row affected (0.00 sec)
mysql> insert into productos value("a02","silla modelo.zaz","200","2009/11/03");
Query OK, 1 row affected (0.00 sec)
mysql> insert into productos value("a03","silla modelo.xax","400","2009/11/03");
Query OK, 1 row affected (0.00 sec)
mysql> insert into productos value("a04","computadora","5500","2009/11/11");
Query OK, 1 row affected (0.00 sec)
mysql> insert into productos value("a05","chicles","12","2009/11/29");
Query OK, 1 row affected (0.00 sec)
mysql> select * from productos;
+--------+------------------+--------+------------+
| codigo | nombre | precio | fechaalta |
+--------+------------------+--------+------------+
| a01 | vinos | 250 | 2009-11-02 |
| a02 | silla modelo.zaz | 200 | 2009-11-03 |
| a03 | silla modelo.xax | 400 | 2009-11-03 |
| a04 | computadora | 5500 | 2009-11-11 |
| a05 | chicles | 12 | 2009-11-29 |
+--------+------------------+--------+------------+
5 rows in set (0.00 sec)
mysql> select * from productos where nombre='vinos';
+--------+--------+--------+------------+
| codigo | nombre | precio | fechaalta |
+--------+--------+--------+------------+
| a01 | vinos | 250 | 2009-11-02 |
+--------+--------+--------+------------+
1 row in set (0.00 sec)
mysql> select * from productos where nombre like 's%';
+--------+------------------+--------+------------+
| codigo | nombre | precio | fechaalta |
+--------+------------------+--------+------------+
| a02 | silla modelo.zaz | 200 | 2009-11-03 |
| a03 | silla modelo.xax | 400 | 2009-11-03 |
+--------+------------------+--------+------------+
2 rows in set (0.00 sec)
mysql> select nombre,precio from productos where precio>433;
+-------------+--------+
| nombre | precio |
+-------------+--------+
| computadora | 5500 |
+-------------+--------+
1 row in set (0.00 sec)
mysql> select avg(precio) from productos where left(nombre,5)='silla';
+-------------+
| avg(precio) |
+-------------+
| 300.0000 |
+-------------+
1 row in set (0.00 sec)
mysql> alter table productos add categoria varchar(10);
Query OK, 5 rows affected (0.05 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> update productos set categoria='utencilio';
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> update productos set categoria='mueble';
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> update productos set categoria='mueble';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0
mysql> select * from productos;
+--------+------------------+--------+------------+-----------+
| codigo | nombre | precio | fechaalta | categoria |
+--------+------------------+--------+------------+-----------+
| a01 | vinos | 250 | 2009-11-02 | mueble |
| a02 | silla modelo.zaz | 200 | 2009-11-03 | mueble |
| a03 | silla modelo.xax | 400 | 2009-11-03 | mueble |
| a04 | computadora | 5500 | 2009-11-11 | mueble |
| a05 | chicles | 12 | 2009-11-29 | mueble |
+--------+------------------+--------+------------+-----------+
5 rows in set (0.00 sec)
EJERCICIO NUMERO 3
mysql> create database productos1;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| materia_prima |
| mysql |
| phpmyadmin |
| productos1 |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql> use productos1;
Database changed
mysql> create table productos(codigo varchar(3), nombre varchar(30), precio deci
mal(6,2), fechaalta date, primary key (codigo));
Query OK, 0 rows affected (0.07 sec)
mysql> insert into productos values ("a01","afilador","2.50","2007-11-02");
Query OK, 1 row affected (0.04 sec)
mysql> insert into productos values ("s01","silla mod. ZAZ",20,"2007-11-02");
Query OK, 1 row affected (0.00 sec)
mysql> insert into productos values ("s02","silla mod.xax",25,"2007-11-03");
Query OK, 1 row affected (0.00 sec)
mysql> select * from productos;
+--------+----------------+--------+------------+
| codigo | nombre | precio | fechaalta |
+--------+----------------+--------+------------+
| a01 | afilador | 2.50 | 2007-11-02 |
| s01 | silla mod. ZAZ | 20.00 | 2007-11-02 |
| s02 | silla mod.xax | 25.00 | 2007-11-03 |
+--------+----------------+--------+------------+
3 rows in set (0.00 sec)
mysql> select * from productos where nombre='afilador';;
+--------+----------+--------+------------+
| codigo | nombre | precio | fechaalta |
+--------+----------+--------+------------+
| a01 | afilador | 2.50 | 2007-11-02 |
+--------+----------+--------+------------+
1 row in set (0.00 sec)
mysql> select * from productos where nombre like 's%';
+--------+----------------+--------+------------+
| codigo | nombre | precio | fechaalta |
+--------+----------------+--------+------------+
| s01 | silla mod. ZAZ | 20.00 | 2007-11-02 |
| s02 | silla mod.xax | 25.00 | 2007-11-03 |
+--------+----------------+--------+------------+
2 rows in set (0.00 sec)
mysql> select nombre, precio from productos where left(nombre,5)='silla';
+----------------+--------+
| nombre | precio |
+----------------+--------+
| silla mod. ZAZ | 20.00 |
| silla mod.xax | 25.00 |
+----------------+--------+
2 rows in set (0.00 sec)
mysql> select nombre, precio from productos where precio >22;
+---------------+--------+
| nombre | precio |
+---------------+--------+
| silla mod.xax | 25.00 |
+---------------+--------+
1 row in set (0.00 sec)
mysql> select avg(precio) from productos where left(nombre,5)='silla';
+-------------+
| avg(precio) |
+-------------+
| 22.500000 |
+-------------+
1 row in set (0.00 sec)
mysql> alter table productos add categoria varchar(10);
Query OK, 3 rows affected (0.07 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> update productos set categoria='utensilio';
Query OK, 0 rows affected (0.00 sec)
mysql> update productos set categoria="silla" where left(nombre,5) ='silla';
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select distinct categoria from productos;
+-----------+
| categoria |
+-----------+
| utensilio |
| silla |
+-----------+
2 rows in set (0.00 sec)
mysql> select categoria, count(*) from productos group by categoria;
+-----------+----------+
| categoria | count(*) |
+-----------+----------+
| silla | 2 |
| utensilio | 1 |
+-----------+----------+
2 rows in set (0.02 sec)
No hay comentarios.:
Publicar un comentario