Empresa completo

download Empresa completo

If you can't read please download the document

Transcript of Empresa completo

1. ---+--------------------+| codigo | nombre | cargo | f_ingreso | salario | comision | cod_dep | departamento_codep |+--------+----------------+------------+------------+---------+----------+---------+--------------------+| 7369 | Carlos Perdomo | SUPERVISOR | 0000-00-00 | 800 | 50 |20 | 10 || 7499 | Fernando Velez | VENDEDOR | 0000-00-00 | 1600 | 300 |30 | 20 || 7521 | Rosario Gomez | VENDEDOR | 0000-00-00 | 2975 | 200 |20 | 30 |+--------+----------------+------------+------------+---------+----------+---------+--------------------+3 rows in set (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || empresa || mysql |+--------------------+3 rows in set (0.00 sec)mysql> drop database empresa;Query OK, 2 rows affected (0.10 sec)mysql>mysql>mysql>mysql>mysql>mysql> create database empresa;Query OK, 1 row affected (0.01 sec)mysql> use empresa;Database changedmysql>mysql>mysql>mysql> create table departamento-> (codep integer(30) PRIMARY KEY,-> nombre_der varchar(30),-> ubicacion varchar(30));Query OK, 0 rows affected (0.05 sec)mysql>mysql> insert into departamento-> values(10,'contabilidad','cali');Query OK, 1 row affected (0.02 sec)mysql>mysql> insert into departamento-> values(20,'investigacion','bogota');Query OK, 1 row affected (0.02 sec)mysql>mysql> insert into departamento-> values(30,'ventas','manizales');Query OK, 1 row affected (0.02 sec)mysql> select * from departamento;+-------+---------------+-----------+ 2. | codep | nombre_der | ubicacion |+-------+---------------+-----------+| 10 | contabilidad | cali || 20 | investigacion | bogota || 30 | ventas | manizales |+-------+---------------+-----------+3 rows in set (0.00 sec)mysql>mysql>mysql> create table empleado-> (codigo integer,-> nombre varchar(30),-> cargo varchar(30),-> f_ingreso date,-> salario integer,-> comision integer,->-> departamento_codep integer,-> PRIMARY KEY (codigo),-> FOREIGN KEY(departamento_codep)-> REFERENCES departamento(codep)-> ON DELETE NO ACTION-> ON UPDATE NO ACTION-> );Query OK, 0 rows affected (0.06 sec)mysql> insert into empleado-> values(7369,'Carlos Perdomo','SUPERVISOR',1980-12-17,800,50,20);Query OK, 1 row affected, 1 warning (0.03 sec)mysql>mysql> insert into empleado-> values(7499,'Fernando Velez','VENDEDOR',1981-02-20,1600,300,30);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado-> values(7521,'Rosario Gomez','VENDEDOR',1981-12-22,2975,200,30);Query OK, 1 row affected, 1 warning (0.01 sec)mysql>mysql> insert into empleado-> values(7566,'Jones Wilson','AUXILIAR',1981-04-21,2975,200,20);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado-> values(7654,'Martin Vanegas','VENDEDOR',1998-03-04,1250,1400,30);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql>mysql> insert into empleado-> values(7698,'Blake Salas','AUXILIAR',2003-08-04,2850,150,30);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado-> values(7782,'Clark Ken','AUXILIAR',2006-11-30,2450,1200,10);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado 3. -> values(7788,'Alma Scott','ANALISTA',2004-07-14,3000,0,20);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql>mysql> insert into empleado-> values(7839,'Clara Lopez','PRESIDENTE',1998-11-11,5000,0,10);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado-> values(7844,'Zoila Estrada','VENDEDOR',2007-10-03,1500,1300,30);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado-> values(7876,'Diego Perez','SUPERVISOR',1999-11-03,1100,100,20);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql>mysql> insert into empleado-> values(7900,'Ximena Rugeles','SUPERVISOR',2000-12-20,950,2500,30);Query OK, 1 row affected, 1 warning (0.01 sec)mysql>mysql> insert into empleado-> values(7902,'Viviana Morales','ANALISTA',2001-11-11,3000,1800,20);Query OK, 1 row affected, 1 warning (0.02 sec)mysql>mysql> insert into empleado-> values(7934,'Tito Lopez','SUPERVISOR',2006-06-05,1300,0,10);Query OK, 1 row affected, 1 warning (0.02 sec)mysql> select * from empleado;+--------+-----------------+------------+------------+---------+----------+--------------------+| codigo | nombre | cargo | f_ingreso | salario | comision | departamento_codep |+--------+-----------------+------------+------------+---------+----------+--------------------+| 7369 | Carlos Perdomo | SUPERVISOR | 0000-00-00 | 800 | 50 |20 || 7499 | Fernando Velez | VENDEDOR | 0000-00-00 | 1600 | 300 |30 || 7521 | Rosario Gomez | VENDEDOR | 0000-00-00 | 2975 | 200 |30 || 7566 | Jones Wilson | AUXILIAR | 0000-00-00 | 2975 | 200 |20 || 7654 | Martin Vanegas | VENDEDOR | 0000-00-00 | 1250 | 1400 |30 || 7698 | Blake Salas | AUXILIAR | 0000-00-00 | 2850 | 150 |30 || 7782 | Clark Ken | AUXILIAR | 0000-00-00 | 2450 | 1200 |10 || 7788 | Alma Scott | ANALISTA | 0000-00-00 | 3000 | 0 |20 || 7839 | Clara Lopez | PRESIDENTE | 0000-00-00 | 5000 | 0 |10 || 7844 | Zoila Estrada | VENDEDOR | 0000-00-00 | 1500 | 1300 |30 || 7876 | Diego Perez | SUPERVISOR | 0000-00-00 | 1100 | 100 |20 | 4. | 7900 | Ximena Rugeles | SUPERVISOR | 0000-00-00 | 950 | 2500 |30 || 7902 | Viviana Morales | ANALISTA | 0000-00-00 | 3000 | 1800 |20 || 7934 | Tito Lopez | SUPERVISOR | 0000-00-00 | 1300 | 0 |10 |+--------+-----------------+------------+------------+---------+----------+--------------------+14 rows in set (0.01 sec)mysql> select count(*) as 'NUMERO EMPLEADOS' from empleado;+------------------+| NUMERO EMPLEADOS |+------------------+| 14 |+------------------+1 row in set (0.03 sec)mysql> select count(DISTINCT CARGO) as 'NUMEROS DE CARGOS' from empleado;+-------------------+| NUMEROS DE CARGOS |+-------------------+| 5 |+-------------------+1 row in set (0.00 sec)mysql> select nombre_der as departamento, count(*) as 'NUMERO DE EMPLEADOS' fromempleado, departamento where codep=deptno group by deptno;ERROR 1054 (42S22): Unknown column 'deptno' in 'where clause'mysql>mysql>mysql>mysql>mysql> select nombre_der as departamento, count(*) as "NUMERO DE EMPLEADOS" fromempleado, departamento where codep=departamento_codep group by departamento_codep;+---------------+---------------------+| departamento | NUMERO DE EMPLEADOS |+---------------+---------------------+| contabilidad | 3 || investigacion | 5 || ventas | 6 |+---------------+---------------------+3 rows in set (0.03 sec)mysql> select cargo, count(*) as "empleados por cargo" from empleado group by cargo;+------------+---------------------+| cargo | empleados por cargo |+------------+---------------------+| ANALISTA | 2 || AUXILIAR | 3 || PRESIDENTE | 1 || SUPERVISOR | 4 || VENDEDOR | 4 |+------------+---------------------+5 rows in set (0.00 sec)mysql> select nombre_der as departamento, sum(salario) as "suma salario" from empleado,departamento where codep=departamento_codep group by departamento_codep;+---------------+--------------+| departamento | suma salario |+---------------+--------------+| contabilidad | 8750 | 5. | investigacion | 10875 || ventas | 11125 |+---------------+--------------+3 rows in set (0.02 sec)mysql> select departamento_codep from empleado group by departamento_codep having sum(salario) >9000;+--------------------+| departamento_codep |+--------------------+| 20 || 30 |+--------------------+2 rows in set (0.00 sec)mysql> select departamento_codep as CODIGO ,nombre_der as NOMBRE from empleado,departamento where codep=departamento_codep group by departamento_codep having sum(salario) >9000;+--------+---------------+| CODIGO | NOMBRE |+--------+---------------+| 20 | investigacion || 30 | ventas |+--------+---------------+2 rows in set (0.00 sec)mysql> select max(salario) as "salario mas alto" from empleado;+------------------+| salario mas alto |+------------------+| 5000 |+------------------+1 row in set (0.00 sec)mysql> select nombre, salario from empleado where salario = (select max(salario)from empleado);+-------------+---------+| nombre | salario |+-------------+---------+| Clara Lopez | 5000 |+-------------+---------+1 row in set (0.03 sec)mysql> 6. | investigacion | 10875 || ventas | 11125 |+---------------+--------------+3 rows in set (0.02 sec)mysql> select departamento_codep from empleado group by departamento_codep having sum(salario) >9000;+--------------------+| departamento_codep |+--------------------+| 20 || 30 |+--------------------+2 rows in set (0.00 sec)mysql> select departamento_codep as CODIGO ,nombre_der as NOMBRE from empleado,departamento where codep=departamento_codep group by departamento_codep having sum(salario) >9000;+--------+---------------+| CODIGO | NOMBRE |+--------+---------------+| 20 | investigacion || 30 | ventas |+--------+---------------+2 rows in set (0.00 sec)mysql> select max(salario) as "salario mas alto" from empleado;+------------------+| salario mas alto |+------------------+| 5000 |+------------------+1 row in set (0.00 sec)mysql> select nombre, salario from empleado where salario = (select max(salario)from empleado);+-------------+---------+| nombre | salario |+-------------+---------+| Clara Lopez | 5000 |+-------------+---------+1 row in set (0.03 sec)mysql>