dimanche 10 juillet 2016

Divide from table each row with the sum of the same table

I have got a query that shows Events and for this events there are durations. To get the Duration I did a calculation in my query:

Sum(cast(EventEndDateTime - EventStartDateTime as float)) as Duration,

The Table:

Event   Duration
[Pr     10,48
[Al     9,89
[To     1,32
[Co     0,41
[Gh     0,33

And I must divide each of this row with the sum of the column Duration. For Example: The Sum of the column Duration is =22,43. --> (10,48/22,43)*100 = 46,72%

I tried this here:

Sum(cast(EventEndDateTime - EventStartDateTime as float)) / (SELECT Sum(cast(EventEndDateTime - EventStartDateTime as float)) From Event) as SumOfDuration

But this gave me not the correct result. I use SSRS

Aucun commentaire:

Enregistrer un commentaire