Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

select en horizontal

8 views
Skip to first unread message

Luis Mata

unread,
Nov 19, 2009, 2:47:15 PM11/19/09
to
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

rgarrigo...@solidq.com

unread,
Nov 19, 2009, 3:12:22 PM11/19/09
to
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

Alejandro Mesa

unread,
Nov 19, 2009, 3:48:01 PM11/19/09
to
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:

> .
>

0 new messages