Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/01/2011, 15:46
gise1985
 
Fecha de Ingreso: noviembre-2010
Mensajes: 6
Antigüedad: 13 años, 5 meses
Puntos: 0
Pregunta duda en consulta sql

hola, tengo una duda y les agradeceria si me pudieran ayudar.

Tengo el siguiente esquema:
Fotografos( id_fotografo , nombre_fotografo)

Reportajes( cod_reportaje ,precio_reportaje , fecha_realizacion , id_fotografo )

Editoriales( cod_editorial , nombre_editorial )

Comprar( cod_editorial , cod_reportaje )

Exclusivas( cod_exclusiva , titulo_exclusiva , precio_exclusiva ,fecha_entrega , cod_editorial )

Solicitar( cod_exclusiva , fecha_solicitud , id_fotografo )


Necesito sacar el importe total a pagar a cada fotografo tanto por sus reportajes realizados como por sus exclusivas entregadas en noviembre de 2010.

Tengo esto:

select distinct f.id_fotografo,sum(r.precio_reportaje)
from fotografos f, reportajes r, comprar c
where (f.id_fotografo = r.id_fotografo) and
(r.cod_reportaje = c.cod_reportaje) and
(r.fecha_realizacion between '01-nov-10' and '30-nov-10')
group by f.id_fotografo
union
select distinct f.id_fotografo, sum(e.precio_exclusiva)
from fotografos f, exclusivas e, solicitar s
where (f.id_fotografo = s.id_fotografo) and
(s.cod_exclusiva = e.cod_exclusiva) and
(e.fecha_entrega between '01-nov-10' and '30-nov-10')
group by f.id_fotografo);

y me resulta:

ID_FOTOGRA SUM(R.PRECIO_REPORTAJE)
---------- -----------------------
gisviva 2000
gisviva 4000
patmeji 400
patmeji 1500
robmore 3000


y yo necesito que me salga :

ID_FOTOGRA SUM(R.PRECIO_REPORTAJE)
---------- -----------------------
gisviva 6000
patmeji 1900
robmore 3000

e intentado de varias maneras pero no lo logro, me he quedado con el resultado menos malo para ponerlo aqui.