0
Guys, in the query below, is bringing the following way.
Ano Mes Horas total_horas
2018 1 107 766 H
2018 1 225 766 H
Therefore, I want you to bring in another column the division of the column "Hours" by the column "total_hours", bringing this way.
Ano Mes Horas total_horas media
2018 1 107 766 H 0,139996
2018 1 225 766 H 0,293735
Follow the query below.
select
t1.Ano,t1.Mês,t1.horas,t2.total_horas
from
(select sum(f.C06) horas, DATEPART(month, TarFechamento) Mês, DATEPART(YEAR, TarFechamento) Ano, FC.Valor Tipo
from Tarefa t
INNER JOIN Usuario u on t.UsuIDResponsavel = u.UsuID and u.UsuIDGrupo = 7
INNER JOIN FRM_10 F ON F.TarefaID = T.TarID AND F.C04 IS NOT NULL
INNER JOIN FormularioCampoValor FC ON FC.ValorID = F.C04
where t.ProID in (9,3,12,7,10,4,5,2) AND T.TarTipID NOT IN (1048,1049,1050) and datepart(year,tarfechamento)>= 2018 and t.TarStatus = 9
group by DATEPART(YEAR, TarFechamento), datepart(month,TarFechamento), FC.Valor)t1
left join
(select concat(cast(sum(f.C06) as varchar(100)),' ','H') total_horas, DATEPART(month, TarFechamento) Mês, DATEPART(YEAR, TarFechamento) Ano
from Tarefa t
INNER JOIN Usuario u on t.UsuIDResponsavel = u.UsuID and u.UsuIDGrupo = 7
INNER JOIN FRM_10 F ON F.TarefaID = T.TarID AND F.C04 IS NOT NULL
INNER JOIN FormularioCampoValor FC ON FC.ValorID = F.C04
where t.ProID in (9,3,12,7,10,4,5,2) AND T.TarTipID NOT IN (1048,1049,1050) and datepart(year,tarfechamento)>= 2018 and t.TarStatus = 9
group by DATEPART(YEAR, TarFechamento), datepart(month,TarFechamento))t2 on t1.Ano = t2.Ano and t1.Mês = t2.Mês
NOTE: I tried to perform in the external consultation above this way however, without success..
select
t1.Ano,t1.Mês,t1.horas / t2.total_horas
t1.hours and t2.total_hours are integer, time or other type?
– Ari Santos
@Arisantos, they are whole
– Renan Bessa
tried in a bank I have for testing and the code select t1.Year,t1.Month,t1.hours / t2.total_hours should have worked which output when you use it?
– Ari Santos
select t1.Year,t1.Month,t1.hours,t2.total_hours,CAST(t1.hours AS FLOAT)/CAST(t2.total_hours AS FLOAT) AS MEDIA
– Diego