Fórum Problema com select duplicando valor? #134651
11/04/2010
0
Problema com select duplicando valor?
Não existe mais
Como não consegui alterar o titulo do post, mudei somente o conteudo do post.
O titulo deveria ser este agora
Como somar total de horas no firebird?
Pessoal estou usando fb 2.0 e preciso saber como somar total de horas no firebird?
select td.idcondutor, td.nomecondutor,
--sum(xd.horatotal) Total_Horas,
sum(xd.kms) Total_KM, count(xd.descrserv) Quantidade_Servicos,
coalesce(sum(xd.vrlcondutor),0) Total_Codutor,
(select coalesce(sum(vl.valor),0)
from vale vl where td.idcondutor = vl.idfunciona
and coalesce(vl.fechamov,'',null) <> 'F')as Total_Despesa
from ordemserv td
inner join servicos xd on
td.idordem = xd.idordem and
td.nomecondutor = xd.nomecondutor
where td.nomecondutor = xd.nomecondutor
and td.idcondutor between :idCondIni and :idCondFin
and td.nomecondutor is not null
and td.idordem = xd.idordem
and td.emissao between :tddataini and :tddatafin
group by td.idcondutor, td.nomecondutor
O comando SUM não é reconhecido para somar total de horas no fb, então como devo fazer?
O campo HORATOTAL é um campo tipo TIME.
Adriano Dolce
Curtir tópico
+ 0Posts
12/04/2010
Adriano Dolce
select td.idcondutor, td.nomecondutor,
sum(xd.kms) Total_KM, count(xd.descrserv) Quantidade_Servicos,
coalesce(sum(xd.vrlcondutor),0) Total_Codutor,
(select
(hora/3600) ||':'||
((hora-((hora)/3600)*3600)/60)||':'||
(hora - (hora/3600)*3600 - ((hora-((hora)/3600)*3600)/60)*60 )
from
(
select
cast(sum(
extract( hour from xd.horatotal ) * 3600 +
extract( minute from xd.horatotal ) * 60 +
extract( second from xd.horatotal )
) as integer) as hora
from servicos xd
where td.idordem = xd.idordem and
td.nomecondutor = xd.nomecondutor))as Total_Horas,
(select coalesce(sum(vl.valor),0)
from vale vl where td.idcondutor = vl.idfunciona
and coalesce(vl.fechamov,'',null) <> 'F')as Total_Despesa
from ordemserv td
inner join servicos xd on
td.idordem = xd.idordem and
td.nomecondutor = xd.nomecondutor
where td.nomecondutor = xd.nomecondutor
and td.idcondutor between :idCondIni and :idCondFin
and td.nomecondutor is not null
and td.idordem = xd.idordem
and td.emissao between :tddataini and :tddatafin
group by td.idcondutor, td.nomecondutor
Mais esta formatando meio estranho a hora
Está saindo assim
1:9:0
4:0:0
Queria que formatasse para sair assim (os segundos não tem necessidade)
01:09
04:00
etc..
se for por exemplo mais de 23:59 horas vai somando
120:40
200:55
etc...
Este select deve trazer o total de horas que o funcionario fez durante o periodo da clausula where.
Gostei + 0
21/04/2010
Adriano Dolce
Mais como fazer este case antes?
select td.idcondutor, td.nomecondutor, sum(xd.kms) Total_KM, count(xd.descrserv) Quantidade_Servicos, coalesce(sum(xd.vrlcondutor),0) Total_Codutor, (select
case hora
when < '10' then '0'
end as hora, (hora/3600) ||':'|| ((hora-((hora)/3600)*3600)/60)||':'|| (hora - (hora/3600)*3600 - ((hora-((hora)/3600)*3600)/60)*60 ) from ( select cast(sum( extract( hour from xd.horatotal ) * 3600 + extract( minute from xd.horatotal ) * 60 + extract( second from xd.horatotal ) ) as integer) as hora from servicos xd where td.idordem = xd.idordem and td.nomecondutor = xd.nomecondutor))as Total_Horas, (select coalesce(sum(vl.valor),0) from vale vl where td.idcondutor = vl.idfunciona and coalesce(vl.fechamov,'',null) <> 'F')as Total_Despesa from ordemserv td inner join servicos xd on td.idordem = xd.idordem and td.nomecondutor = xd.nomecondutor where td.nomecondutor = xd.nomecondutor and td.idcondutor between :idCondIni and :idCondFin and td.nomecondutor is not null and td.idordem = xd.idordem and td.emissao between :tddataini and :tddatafin group by td.idcondutor, td.nomecondutor
Gostei + 0
24/04/2010
Adriano Dolce
select td.idcondutor, td.nomecondutor, sum(xd.kms) Total_KM, count(xd.descrserv) Quantidade_Servicos, coalesce(sum(xd.vrlcondutor),0) Total_Codutor, (select case when (HORA/3600) < 10 then '0'||(HORA/3600) else (HORA/3600) end ||':'|| case when ((HORA-((HORA)/3600)*3600)/60) < 10 then '0'||((HORA-((HORA)/3600)*3600)/60) else ((HORA-((HORA)/3600)*3600)/60) end from ( select cast(sum( extract( hour from xd.horatotal ) * 3600 + extract( minute from xd.horatotal ) * 60 + extract( second from xd.horatotal ) ) as integer) as hora from servicos xd where td.idordem = xd.idordem and td.nomecondutor = xd.nomecondutor))as Total_Horas, (select coalesce(sum(vl.valor),0) from vale vl where td.idcondutor = vl.idfunciona and coalesce(vl.fechamov,'',null) <> 'F')as Total_Despesa from ordemserv td inner join servicos xd on td.idordem = xd.idordem and td.nomecondutor = xd.nomecondutor where td.nomecondutor = xd.nomecondutor and td.idcondutor between :idCondIni and :idCondFin and td.nomecondutor is not null and td.idordem = xd.idordem and td.emissao between :tddataini and :tddatafin group by td.idcondutor, td.nomecondutor
Gostei + 0
04/07/2010
Carlos Mazzi
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)