Click here to Skip to main content
15,446,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can't get my head around this.

I need to get 30% of an integer and then reduce the entire column by that amount.
First off I have:

SELECT Quantity, (COUNT(Quantity)*100/(Select COUNT(*) From FishStock)) as Score
FROM Stock
Group By Quantity

Which returns 50% in a new query column. Can't get my head around the maths to convert that to 30% and I literally have no idea how to remove that number to the actual database.

Any help would be most appreciated. Even if you just point me in the right direction.


1 solution

SELECT Quantity, Quantity * 30 / 100 as Score
FROM Stock
Group By Quantity
should give you 30% of quantity in the Score column,

To save this in the database, you need to use an UPDATE query.

Update Stock Set Quantity = Quantity * 30 / 100 will update all quantities to 30% of their initial values. Use this query with extreme caution.
Share this answer
WurmInfinity 10-Dec-11 5:26am    
Thanks dude!. I knew it wasn't as complicated as I was trying to make it seem :D
Abhinav S 10-Dec-11 5:30am    
You are welcome. Be careful with the update query. You ideally may want to run updates on the appropriate row.
WurmInfinity 10-Dec-11 5:31am    
Yeah I think I'll specify the details a bit more. I just needed the general jist of things to get me going :) Thanks again!

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