Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey good people. i have two subqueries.they are as follows
HTML
1- count of total houses = 5
2- count of houses with TV = 3


Now i want to calculate the percentage of houses with TVs, here is expression am using

SQL
% Houses with TV: 100/[totalhousesswithTV].[countofhouseid]*[totalhouses].[countofhouseid]


am getting a wrong result, am getting 166.66666667, instead of 60. whats wrong with the expression
Posted
Updated 11-Aug-12 10:31am
v2

1 solution

This is caused by the Order of operations[^] try using instead:
% Houses with TV: 100/([totalhousesswithTV].[countofhouseid]*[totalhouses].[countofhouseid])
or
% Houses with TV: [totalhousesswithTV].[countofhouseid]/[totalhouses].[countofhouseid]*100
 
Share this answer
 
Comments
mayeso 13-Aug-12 5:31am    
thanks both options works perfect.thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900