1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
WITH SR1 AS (Select [Num],[nom],
Sum( Poids) PoidsTotal
from [dbo].[Rapports] Group By [Num] , [nom]
) , SR2 AS ( Select [Num],[nom],
Sum( Poids) PoidsAnnee
from [dbo].[Rapports] Where Year([Date]) = 2023 Group By [Num], [nom]
), SR3 AS ( Select [Num],[nom],
Sum( Poids) PoidsMois
from [dbo].[Rapports] Where Month([Date]) = 6 and Year([Date]) = 2023 Group By [Num], [nom]
), SR4 as (Select [Num],[nom],
Sum( Poids) PoidsJours
from [dbo].[Rapports] Where Month([Date]) = 6 and Year([Date]) = 2023 and Day([Date]) = 30 Group By [Num], [nom]
), SR5 as (Select [Num],[nom],
Sum( Poids) PoidsSel
from [dbo].[Rapports] Where [Date] between Convert(datetime,'2023-06-30 08:00:00.000',20) and Convert(datetime,'2023-07-03 17:00:00',20) Group By [Num], [nom]
),SR6 as (Select [Num],
Sum( Poids) PoidsSemaine
from [dbo].[Rapports] Where DATEPART(Wk,[Date]) = DATEpart(wk,'26-06-2023') Group By [Num]
)
select SR1.Num,SR1.nom, ISNull(SR1.PoidsTotal,0) As Total, ISNull(SR2.PoidsAnnee,0) as Annee , ISNull(SR3.PoidsMois,0) As Mois, ISNull(SR4.PoidsJours,0) As Jours , ISNull(SR5.PoidsSel,0) As 'Période indiqué', ISNull(SR6.PoidsSemaine,0) As 'Semaine'
FROM SR1
FULL OUTER JOIN SR2 on SR1.Num = SR2.Num
FULL OUTER JOIN SR3 on SR1.Num = SR3.Num
FULL OUTER JOIN SR4 on SR1.Num = SR4.Num
FULL OUTER JOIN SR5 on SR1.Num = SR5.Num
FULL OUTER JOIN SR6 on SR1.Num = SR6.Num
order by num |
Partager