Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL calculations

Status
Not open for further replies.

heydyrtt

Programmer
Joined
Dec 12, 2001
Messages
63
Location
US
Hello,

I need to do a calculation of two fields, field1 / field2 then need to get the percentage of the result from divide by 100%. Below is what I have written so far, which it works, but doesn't give the right percentage.

SELECT a.items, a.orders, c.items_credited, SUM(c.items_credited) / (a.items)-100
FROM credits c, invoice a
WHERE a.county_id = c.county_id
GROUP BY c.items_credited

Items will be a number like 2356, items credited by like 5, I'm dividing 5 from 2356 then -100, which is not giving the right results. Is there a better to do this to get the percentage.

Thanks


Heydyrtt
 
It's your math that's wrong.

Divide the first number by the second. Then multiply that result by 100 to get a percentage.





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
K, thanks, knew I was doing something wrong

Heydyrtt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top