Tirar média de horas
Bom dia pessoal, olha eu aqui novamente.
Estou com uma dúvida muito cruel.
Ainda com aqueles atendimentos. Eu tenho a quantidade de atendimentos que um Atendente fez. Exemplo:
João tem 156 Atendimentos.
E eu também tenho o total de horas que o joão trabalhou em todos os atendimentos. Exemplo:
João tem 156 Atendimentos e 05:59:15 de Tempo Total dos seus Atendimentos.
Como eu faço pra tirar a média de cada atendimento com base nessas informações?
Eu sei que é dividir o total de atendimentos pelo tempo total. Mas como faço isso no Delphi ou pelo próprio select?
Uso Delphi XE
Estou com uma dúvida muito cruel.
Ainda com aqueles atendimentos. Eu tenho a quantidade de atendimentos que um Atendente fez. Exemplo:
João tem 156 Atendimentos.
E eu também tenho o total de horas que o joão trabalhou em todos os atendimentos. Exemplo:
João tem 156 Atendimentos e 05:59:15 de Tempo Total dos seus Atendimentos.
Como eu faço pra tirar a média de cada atendimento com base nessas informações?
Eu sei que é dividir o total de atendimentos pelo tempo total. Mas como faço isso no Delphi ou pelo próprio select?
Uso Delphi XE
Marlon Minotti
Curtidas 0
Melhor post
Marlon Minotti
25/09/2014
Acabei de conseguir, fiz a maior gambiarra do universo. Se liga no código:
select
atendentee as Atendente, total as "Total Atendimentos", Fechadas, Pendentes, Suspensas,
(case when (media/3600) < 10 then 0||(media/3600) else (media/3600) end ||':'||
case when ((media-((media)/3600)*3600)/60) < 10 then 0||((media-((media)/3600)*3600)/60) else ((media-((media)/3600)*3600)/60) end ||':'||
case when (media - (media/3600)*3600 - ((media-((media)/3600)*3600)/60)*60 ) < 10
then '0'||(media - (media/3600)*3600 - ((media-((media)/3600)*3600)/60)*60 ) else
(media - (media/3600)*3600 - ((media-((media)/3600)*3600)/60)*60 ) end) as "Media",
(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 ||':'||
case when (HORA - (HORA/3600)*3600 - ((HORA-((HORA)/3600)*3600)/60)*60 ) < 10
then '0'||(HORA - (HORA/3600)*3600 - ((HORA-((HORA)/3600)*3600)/60)*60 ) else
(HORA - (HORA/3600)*3600 - ((HORA-((HORA)/3600)*3600)/60)*60 ) end) as "Horas Totais"
from(SELECT
atendentee, total, Fechadas, Pendentes, Suspensas, (segundos/total) as media, HORA
from (select s.atendente as atendentee,
count(*) as total,
CAST(SUM(
EXTRACT( HOUR FROM s.hora_total ) * 3600 +
EXTRACT( MINUTE FROM s.hora_total ) * 60 +
EXTRACT( SECOND FROM s.hora_total ))as integer) AS HORA,
CAST(SUM(
EXTRACT( HOUR FROM s.hora_total ) * 3600 +
EXTRACT( MINUTE FROM s.hora_total ) * 60 +
EXTRACT( SECOND FROM s.hora_total ))as integer) AS Segundos,
count(case when s.status = 1 then 1 end) as Fechadas,
count(case when s.status = 0 then 1 end) as Pendentes,
count(case when s.status = 2 then 1 end) as Suspensas
FROM servicos s where 1=1 and s.atendente like 'EDEMI%' group by s.atendente))
select
atendentee as Atendente, total as "Total Atendimentos", Fechadas, Pendentes, Suspensas,
(case when (media/3600) < 10 then 0||(media/3600) else (media/3600) end ||':'||
case when ((media-((media)/3600)*3600)/60) < 10 then 0||((media-((media)/3600)*3600)/60) else ((media-((media)/3600)*3600)/60) end ||':'||
case when (media - (media/3600)*3600 - ((media-((media)/3600)*3600)/60)*60 ) < 10
then '0'||(media - (media/3600)*3600 - ((media-((media)/3600)*3600)/60)*60 ) else
(media - (media/3600)*3600 - ((media-((media)/3600)*3600)/60)*60 ) end) as "Media",
(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 ||':'||
case when (HORA - (HORA/3600)*3600 - ((HORA-((HORA)/3600)*3600)/60)*60 ) < 10
then '0'||(HORA - (HORA/3600)*3600 - ((HORA-((HORA)/3600)*3600)/60)*60 ) else
(HORA - (HORA/3600)*3600 - ((HORA-((HORA)/3600)*3600)/60)*60 ) end) as "Horas Totais"
from(SELECT
atendentee, total, Fechadas, Pendentes, Suspensas, (segundos/total) as media, HORA
from (select s.atendente as atendentee,
count(*) as total,
CAST(SUM(
EXTRACT( HOUR FROM s.hora_total ) * 3600 +
EXTRACT( MINUTE FROM s.hora_total ) * 60 +
EXTRACT( SECOND FROM s.hora_total ))as integer) AS HORA,
CAST(SUM(
EXTRACT( HOUR FROM s.hora_total ) * 3600 +
EXTRACT( MINUTE FROM s.hora_total ) * 60 +
EXTRACT( SECOND FROM s.hora_total ))as integer) AS Segundos,
count(case when s.status = 1 then 1 end) as Fechadas,
count(case when s.status = 0 then 1 end) as Pendentes,
count(case when s.status = 2 then 1 end) as Suspensas
FROM servicos s where 1=1 and s.atendente like 'EDEMI%' group by s.atendente))
GOSTEI 1
Mais Respostas
Fabiano Carvalho
25/09/2014
Qual SGBD?
Se for SQL Server, basta converter as horas para float e realizar a operacao e depois voltar para datetime.
Se for SQL Server, basta converter as horas para float e realizar a operacao e depois voltar para datetime.
GOSTEI 0
Marlon Minotti
25/09/2014
Firebird
GOSTEI 0
Marlon Minotti
25/09/2014
Editando... Não consegui galera. Deu errado. Preciso fazer esse calculo no select. Alguem pode me ajudar?
GOSTEI 0
Marlon Minotti
25/09/2014
Mais Fácil: Eu consigo dividir um valor HH:MM:SS por um valor inteiro? Tipo: 12:30:45 / 10
Se tiver alguma função no firebird que faça isso, eu agradeço. No mysql pelo que pesquisei tem um jeito de fazer +- assim:
SELECT SEC_TO_TIME(TIME_TO_SEC('12:30:45') / 10)
No Firebird tem algo parecido?
Se tiver alguma função no firebird que faça isso, eu agradeço. No mysql pelo que pesquisei tem um jeito de fazer +- assim:
SELECT SEC_TO_TIME(TIME_TO_SEC('12:30:45') / 10)
No Firebird tem algo parecido?
GOSTEI 0
Fabiano Carvalho
25/09/2014
Tenta converter para float, no windows as horas ficam armazenadas internamente como numeros, exemplo, coloque qualquer hora em alguma célula do excel depois va em formatar celula e escolha numeros.
GOSTEI 0