select en horizontal

19/11/2009 - 20:47 por Luis Mata | Informe spam
Hola
se puede poner esto:

select sum(total) as tot_efe from tabla where tpago='efe'

y

select sum(total) as tot_cre from tabla where tpago='cre'

los resultados ponerlo en una sola tabla:

tot_efe tot_cre
150 55

Luis

Preguntas similare

Leer las respuestas

#1 rgarrigos-sinesto
19/11/2009 - 21:12 | Informe spam
Hola Luis,

select
sum(case when tpago='efe' then total else 0 end) as tot_efe,
sum(case when tpago='cre' then total else 0 end) as tot_cre
from
tabla
where
tpago='efe' or tpago='cre'


Un saludo,

Rubén Garrigós
Solid Quality Mentors

Blog: http://blogs.solidq.com/es/elrincondeldba

Hola
se puede poner esto:
select sum(total) as tot_efe from tabla where tpago='efe'

y

select sum(total) as tot_cre from tabla where tpago='cre'

los resultados ponerlo en una sola tabla:

tot_efe tot_cre
150 55
Luis

Respuesta Responder a este mensaje
#2 Alejandro Mesa
19/11/2009 - 21:48 | Informe spam
Luis,

select
(select sum(total) as tot_efe from tabla where tpago='efe') as tot_efe,
(select sum(total) as tot_cre from tabla where tpago='cre') as tot_cre

Tambien puedes hacerlo de la sgte manera:

select
sum(case when tpago = 'efe' then total else 0 end) as tot_efe,
sum(case when tpago = 'cre' then total else 0 end) as tot_cre
from
tabla
where
tpago in ('efe', 'cre');


AMB


"Luis Mata" wrote:

Hola
se puede poner esto:

select sum(total) as tot_efe from tabla where tpago='efe'

y

select sum(total) as tot_cre from tabla where tpago='cre'

los resultados ponerlo en una sola tabla:

tot_efe tot_cre
150 55

Luis
.

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida