• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange Number Problem

 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is some code I am using to count the number of rows in a database whos magnitude levels are either above or below an estimate value.

All the values in my database are below 6.

This works fine unitl I set the integer estimate to be 10 or above.

When I set it to 10 or above I get the reply of 7 above and 3 below.

I do have 3 values that are between 1 and 1.9 though.

Can anyone see any reason why this could be?

All the queries run fine if I run them on the database themselves.

Could it be to do with the way Java creates the number 10 or above?



[ January 22, 2007: Message edited by: Darren Jackson ]
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your query looks like this, right?
SELECT COUNT(Magnitude) FROM Objects WHERE Magnitude < "10" ORDER BY Magnitude ASC
Then you're doing a text comparison, not a numeric comparison. In a text comparison, "10" comes alphabetically before "6". Drop the quotes if you want a numeric comparison.
 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply.

It turns out that the problem was the way the SQL database was set up.

Cheers.

Darren
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic