tags:

views:

58

answers:

1

Look at the strange problem on MYSQL. alt text

Look at the column 3. The result is 0.02876121 but the actually result should be the column 4 = 0.02876. Why is MYSQL giving fault value on decimal points?

*Another thing is that, it only give wrong value if I append "Where column = 'uniquevalue'" to return the result i want. The value is correct if I remove where condition, giving all the records in table.

A: 

I suspect that its all to do with data types used in the calculations.

If 'rank' and 'program_count' are a mix on integers and decimal then SUM() will return a decimal value otherwise it will return a float value. Otherwise SUM() will give a float or double.

In SQL float and double are approximate values, you can define the level of accuracy with the Float keyword.

In your table what data types are the various columns?

ChrisBD
Both the rank and program data type are integer. The value should be exactly 0.02876 and I wonder where the value "121" at the back come from?
neobie
What data type is the output column - marked "sum(rank/program_count)/count(*)" on your diagram? Is it float, double or decimal?
ChrisBD
How do I look at the data type on diagram? Where is it?
neobie