0

Basically I have a table on my server that is a mirror of another table minus some rows I don't care about. I'm trying to use the number of rows and the max ID to determine what percentage of rows were skipped when copying the table.

I've never done math in a SQL query before, and it's probably something simple I'm missing.

Here is my query:

SELECT 
count(*) As Processed,
MAX(ID) - count(*) As Ignored,
MAX(ID) as Total,
(MAX(ID) - count(*)) / MAX(ID) as PercentIgnored
FROM Table

Here are the results

Processed   Ignored    Total        PercentIgnored
6213074     8462494    14675568     0

If I manually calculate 8462494/14675568 it's obviously not zero. More like 57%.

1 Answers1

1

You can try like below as well other than casting to a float type as pointed in the linked post.

SELECT MAX(ID)*1.0 / (MAX(ID) + count(*)) as PercentIgnored from student
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • I just realized all my other numbers were reversed but this still answered my question. Thanks! –  Jun 03 '15 at 19:22