Saludos, tengo un pequeño problema, en mi ER, tengo dos tablas relacionadas:
identificador(id,identificador,descripcion) -> datos(id_datos,total_lunes,total_martes,....,total _domingo,total_total).
Este es el SQL de las tablas:
Código:
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 21/01/2010 09:27:33 a.m. */
/*==============================================================*/
drop table if exists DATOS;
drop table if exists IDENTIFICADOR;
/*==============================================================*/
/* Table: DATOS */
/*==============================================================*/
create table DATOS
(
ID_DATOS int not null,
ID_IDENTIFICADOR int,
TOTAL_LUNES decimal(10,3) not null,
TOTAL_MARTES decimal(10,3) not null,
TOTAL_MIERCOLES decimal(10,3) not null,
TOTAL_JUEVES decimal(10,3) not null,
TOTAL_VIERNES decimal(10,3) not null,
TOTAL_SABADO decimal(10,3) not null,
TOTAL_DOMINGO decimal(10,3) not null,
TOTAL_TOTAL decimal(10,3) not null,
primary key (ID_DATOS)
);
alter table DATOS comment 'entidad que almacena los datos';
/*==============================================================*/
/* Table: IDENTIFICADOR */
/*==============================================================*/
create table IDENTIFICADOR
(
ID_IDENTIFICADOR int not null,
IDENTIFICADOR varchar(25) not null,
DESCRIPCION text not null,
primary key (ID_IDENTIFICADOR)
);
alter table IDENTIFICADOR comment 'Entidad para identificar';
alter table DATOS add constraint FK_REL_IDENTIFICADOR_DATOS foreign key (ID_IDENTIFICADOR)
references IDENTIFICADOR (ID_IDENTIFICADOR) on delete restrict on update restrict;
se me ha dado la tarea de hacer lo siguiente:
Asumiendo que los datos de la tabla identificador tiene los siguientes datos:
id - identificador - descripcion
--------------------------------------------------------
1 - Producción - Cantidad de frutos Producidos por invernadero
2 - SV - Sanidad Vegetal, es la cantidad de Plantas desechadas o eliminadas.
3 - Horas - Cantidad de horas laboradas por los empleados
4 - Poda - Cantidad de plantas Podadas en los invernaderos por canaleta
Asumiendo que la tabla datos tiene la siguiente informacion:
id - id_identificador - total_lunes - total_martes - total_miercoles - total_jueves - total_viernes - total_sabados - total_domingo - total_total
--------------------------------------------------------------------------------------------------------
1 - 1 - 15 - 50 - 20 - 10 - 60 - 70 - 80 - 305
2 - 1 - 5 - 5 - 20 - 10 - 40 - 70 - 10 - 160
3 - 2 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 28
4 - 2 - 7 - 6 - 5 - 4 - 3 - 2 - 1 - 28
Necesito que hacer una consulta a la base de datos para que me muestre la informacion así:
| 1 | 2 | 3 | 4 |<= registros de la tabla indentificador, titulo de columnas cada uno corresponde a Produccion, SV, ...
| 305 | 0 | 0 | 0 |
| 160 | 0 | 0 | 0 |
| 0 | 28 | 0 | 0 |
| 0 | 28 | 0 | 0 |
Yo quiero que el resultado sea el siguiente:
| Produccion | SV | Horas | Poda|
| 305 | 28 | 0 | 0 | <= Los totales (atributo total_total de la entidad datos)
| 160 | 28 | 0 | 0 |<= Los totales (atributo total_total de la entidad datos)
Pues no encuentro en Internet como hacer esa consulta de que los registros de una tabla se muestren en fila y mostrar los datos relacionados tambien en fila.
Será que necesito un Join,InnerJoin,Match,Distinc o algo así pues me he topado allí. Espero respuesta, gracias.