Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

how can I get a percentual in my query from a total field?

Hello guys

I have this query:

SELECT CLIENT, TOTAL FROM SELL

Unless I have the Total, I want the percentual

is it possible? thanks
SOLUTION
Avatar of Imran Javed Zia
Imran Javed Zia
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry miss the @ before sumTotal
Declare @sumTotal float
select @sumTotal = sum(TOTAL) from SELL

SELECT CLIENT, TOTAL, (TOTAL / @sumTotal) as [Percentage] FROM SELL

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

THANKS VERY MUCH
you must select the sum of Total in a variable separately in-order to enhance performance