Fórum Soma de intervalos #463497
09/12/2013
0
preciso retonar em uma mesma query a soma dos resultados de duas querys, onde cada uma retorna um intervalo.
As querys são:
select sum(age(contador_tempo.fim, contador_tempo.inicio)) as intervalo1 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is not null) select sum(age(now(), contador_tempo.inicio)) as intervalo2 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is null)
Eu preciso do resultado de intervalo1 + intervalo2.
Grato,
Rafael Saldanha
Curtir tópico
+ 0Posts
10/12/2013
Alex Lekao
select sum(intervalo1+intervalo2) as intervalo from ( select sum(age(contador_tempo.fim, contador_tempo.inicio)) as intervalo1 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is not null) union select sum(age(now(), contador_tempo.inicio)) as intervalo2 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is null) ) as interval
Gostei + 0
10/12/2013
Rafael Saldanha
Com ajuda de outros colegas cheguei a esta solução:
select ( select sum(age(contador_tempo.fim, contador_tempo.inicio)) as intervalo1 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is not null) ) + ( select sum(age(now(), contador_tempo.inicio)) as intervalo2 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is null) )
Abraços
Gostei + 0
11/12/2013
Alex Lekao
pensei que em outra coisa completamente diferente... rsrsr
nem passou pela minha cabeca so somar os dois selects.. rsrsr
viajei... foi mal.. rsrsr
que bom que resolveu. rsrsr
Abraco.
Alex - Lekao
Gostei + 0
19/05/2014
Marisiana Battistella
select (res.intervalo2 + res.intervalo1) as intervalo_total from ( select sum(age(now(), contador_tempo.inicio)) as intervalo2, sum(age(contador_tempo.fim, contador_tempo.inicio)) as intervalo1 from contador_tempo where contador_tempo.area = 0 and contador_tempo.atendimento = 3045 and (contador_tempo.inicio is not null and contador_tempo.fim is null) ) res
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)