Re: SQL - Calculate 100%

  • From: Eriovaldo Andrietta <ecandrietta@xxxxxxxxx>
  • To: Adam Musch <ahmusch@xxxxxxxxx>
  • Date: Thu, 25 Nov 2010 21:43:56 -0200

Hi Adam,

  I got a solution for the second situation:

                    CASE WHEN  (TRUNC (SUM(vov.viavel) / SUM(vo.total) *
100, 2) +
                                TRUNC (SUM(vnv.nviavel) / SUM(vo.total) *
100, 2) +
                                TRUNC (SUM(vne.nencontr) / SUM(vo.total) *
100, 2)) = 100
                         THEN
                                TRUNC (SUM(vov.viavel) / SUM(vo.total) *
100, 2)
                    ELSE  (TRUNC (SUM(vov.viavel) / SUM(vo.total) * 100, 2)
+
                          100 - (TRUNC (SUM(vov.viavel) / SUM(vo.total) *
100, 2) +
                                 TRUNC (SUM(vnv.nviavel) / SUM(vo.total) *
100, 2) +
                                 TRUNC (SUM(vne.nencontr) / SUM(vo.total) *
100, 2)))
                    END PERCENTUAL_VIAVEIS,

 It solved my issue.

Thanks a lot
Eriovaldo

On Thu, Nov 25, 2010 at 9:18 PM, Eriovaldo Andrietta
<ecandrietta@xxxxxxxxx>wrote:

> Great Adam,
>
>  It solved part of my issue.
>  The ratio_to_report helped when I have this situation:
>
>    10,90
>      3,70
>     85,39
>   (only one column)
>
>  but I also have the situation
>
>   col1         col2       col3
>    --------      --------     --------
>   10,90      3,70       85,39 --> the sum must be 100%
>    (three different columns)
>
> Any other clue ?
>
> I am trying to use DECODE , but the code will not be clear.
>
> Best Regards
> Eriovaldo
>
>
> On Thu, Nov 25, 2010 at 3:08 PM, Adam Musch <ahmusch@xxxxxxxxx> wrote:
>
>> The RATIO_TO_REPORT analytic function appears to be what you're looking
>> for.
>>
>>
>> On Thu, Nov 25, 2010 at 3:57 AM, Eriovaldo Andrietta <
>> ecandrietta@xxxxxxxxx> wrote:
>>
>>> Hi friends,
>>>
>>>  I have the following situation:
>>>
>>> Value1                     Value2        Value2 / Value1 = Percent
>>>
>>>   4128,00 450,00 10,90  4128,00 153,00 3,70  s4128,00 3525,00 85,39
>>> Sum Percent ------------------->                    99,99
>>>
>>> The sum of percent is not 100% ...
>>>
>>>   Is there any SQL instruction that does this calculation and adjust the
>>> value to 100% ?
>>>
>>> Regards
>>>  Eriovaldo
>>>
>>
>>
>>
>> --
>> Adam Musch
>> ahmusch@xxxxxxxxx
>>
>
>

Other related posts: