Galera, in the query below, is as follows.
Ano Mes Horas total_horas
2018 1 107 766 H
2018 1 225 766 H
So, I want you to bring in another column the division of the column "Hours" by the column "total_horas", 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 query above this way, but without success ..
select
t1.Ano,t1.Mês,t1.horas / t2.total_horas