SQL - Select anidados

 
Vista:

Select anidados

Publicado por Paco (2 intervenciones) el 04/10/2011 19:05:58
Hola, a ver tengo un problema con una consulta SQL con varias subconsultas. Necesito sacar por columnas unos campos calculados que estan en uan tabla agrupados por un campo.

Si lanzo esta SQL con dos select anidados solo o 3, funciona (tarda mucho, pero me saca lo que quiero.. si sabeis alguna otra forma..). El problema esta en cuando al lanzo completo que me dice que devuelve mas de un valor la subconsulta.

A ver si me podeis ayudar gracias...


select F.numfact,

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='AL') as 'FUNGIBLES',

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='AN') as 'ANESTESIA',

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='DQ') as 'D.QUIROFANO',

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='ES') as 'ESTANCIAS',

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='FA') as 'FARMACOS',

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='HM') as 'H.MEDICOS',

(select SUM(F.totlinea) from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='PR') as 'PRESTACIONES',


(select cf.dconc from IFMSFA_LINPDEFP_V F left join IFMSFA_CONCEPTOS cf on f.rconc=cf.rconc and f.econc=cf.econc
where F.ffactura between '01/09/2011' and '01/09/2011' and F.gserreal in ('13010','13020','13030','13040')and f.rconc='PR') as 'DESC.CONCEPTO',sum(F.totlinea)

from IFMSFA_LINPDEFP_V F
where F.ffactura between '01/09/2011' and '01/09/2011'
and F.gserreal in ('13010','13020','13030','13040')
group by F.numfact
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Select anidados

Publicado por Paco (2 intervenciones) el 05/10/2011 10:28:57
Me acabo de dar cuenta que esta consulta cuando le meto mas de un dia me devuelve mas de un valor, logico.. se os ocurre de alguna manera que pueda hacer esto?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar