This doesn't work if sum(balance) = 0. I decided to do in two steps (adding the percentage).
>select Account, sum(balance) as Total_Balance, sum(iif(MyCond,value,0)) as MyCond_Balance, sum(iif(MyCond,value,0)) / sum(balance) AS nperc from ... group by 1 having nperc > 0.1 (10 %)
>
>This should work fine
>
>>>Hi everybody,
>>>
>>>Using VFP8 do you think it's possible to do something like
>>>
>>>select Account, sum(balance) as Total_Balance, sum(iif(MyCond,value,0)) as MyCond_Balance from ... group by 1 having MyCond_Balance/Total_Balance > 0.1 (10 %)
>>>
>>>I also need to include percent into result.
>>>
>>>Or do you think I should better do this in 2 select statements to get all balances first and then filter based on 10% condition?
>>>
>>>Thanks in advance.
>>
>>Well, one select statement worked fine. Now I just have to figure out if it's possible to add percent directly into the select statement. If not, I'll add it as a separate update.
If it's not broken, fix it until it is.
My Blog