Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Firebird e Interbase (https://www.clubdelphi.com/foros/forumdisplay.php?f=19)
-   -   Select anidado ( Select from select ) (https://www.clubdelphi.com/foros/showthread.php?t=14885)

Malon 04-10-2004 16:47:12

Select anidado ( Select from select )
 
Hola a todos.

Tengo una consulta de este tipo:

SELECT V.Nivel , Sum(V.CanNuevos) as CantNue, Sum(V.CanBajas) as CantBaj
FROM [Select count(*) as CanNuevos, Sum(0) as CanBajas, Nivel
From Alumnos
Where Ano_Ingreso=:nA1
Group by Nivel
union
Select Sum(0) as CanNuevos, count(*) as CanBajas, Nivel
From Alumnos
Where Ano_Baja=:nA2
Group by Nivel]. as V
GROUP BY V.Nivel
ORDER BY V.Nivel

El select de union daria un resultado mas o menos asi:

Nivel CantNue CantBaj
-------------------------
1 10 0
1 0 20
2 15 0
2 0 35

Y lo que yo necesito es poder agruparlo por nivel:

Nivel CantNue CantBaj
-------------------------
1 10 20
2 15 35

Esto en Acces funciona y creo que en SQLServer tambien, pero en Firebird no.
Se podria resolver utilizando un vista para Select de union:

SELECT V.Nivel , Sum(V.CanNuevos) as CantNue, Sum(V.CanBajas) as CantBaj
FROM Vista_Union as V
GROUP BY V.Nivel
ORDER BY V.Nivel

pero necesito mandarle parametros.

Alguien puede ayudarme ?????

Chaja 05-10-2004 04:14:38

Master....
 
Yo en mi humilde opinio haría un store

:-)

for SELECT V.Nivel , Sum(V.CanNuevos) as CantNue, Sum(V.CanBajas) as CantBaj
FROM Alumnos
into :xx:xc....
Where Ano_Ingreso=:nA1 do
begin
hago otro, select etc.
end

si lo debes llamar desde la aplicacion cliente no hay problema, y le podes pasar los parametros. Con una vista no vas a poder al menos nunca las hice pero creo que no se le pueden pasar parametros..


La franja horaria es GMT +2. Ahora son las 22:26:13.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi