Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Dividing but getting 0's in SQL Statement

$
0
0
I'm using a subquery to pull out sums and counts, and trying to divide one number by another. The results I get when I do the division are all 0's, except in cases where the divided numbers are 1 and 1, thus giving me a 1 back.

Here is my structure

SELECT
SALES_ID,
COUNT(P_CODE) AS "TOTAL WORK ORDERS",
SUM(AVOIDABLE_FLAG) AS AVOIDABLE,
SUM(AVOIDABLE_FLAG)/COUNT(P_CODE) AS AVOIDABLE_RATE
FROM (****subquery here) A

GROUP BY SALES_ID


How can I get the "Avoidable Rate" to come back in a decimal format, or even a percentage if that is possible. I'm relatively new to SQL and haven't quite figured this one out yet. I'm pulling from a db2 server and using MS ACCESS to pass-through, making declaring any variables difficult.

Viewing all articles
Browse latest Browse all 13329