I have above table and I want to get the highest value from table bids where bid_id=60 using the following query
SELECT MAX(offer_amount) as maz FROM bids WHERE bid_id = 60
The problem is I'm getting the result as 80 in instead of the correct value which is 7000000
Anybody with an idea of how to solve this?
Jonathan Leffler
759k145 gold badges961 silver badges1.3k bronze badges
asked Sep 8, 2016 at 6:27
Nicholas Macharia
1242 silver badges9 bronze badges
-
Aberrant case. Would you please share an sql fiddle ?1000111– 10001112016年09月08日 06:30:06 +00:00Commented Sep 8, 2016 at 6:30
-
5It's "correct". And store integers as integers and strings as stringsStrawberry– Strawberry2016年09月08日 06:31:18 +00:00Commented Sep 8, 2016 at 6:31
-
@Strawberry it have worked I have changed the amount_column from VARCHAR to INTNicholas Macharia– Nicholas Macharia2016年09月08日 06:39:58 +00:00Commented Sep 8, 2016 at 6:39
-
Well, of course;-)Strawberry– Strawberry2016年09月08日 06:41:27 +00:00Commented Sep 8, 2016 at 6:41
-
You can get desired output by using CAST but what about if you perform SUM, AVG function in that column again you have to use CAST where ever you need and it's not correct way.Shushil Bohara– Shushil Bohara2016年09月08日 06:42:24 +00:00Commented Sep 8, 2016 at 6:42
1 Answer 1
Store offer_amount in a numeric field (such as integer or decimal), not as text. Quick solution is to use the CAST() function in the query to cast the field's data type to a numeric one.
answered Sep 8, 2016 at 6:31
Shadow
34.5k10 gold badges67 silver badges76 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Jonathan Leffler
And we can tell it's a string, not a number, because the values are left-justified in the displayed fragment of the table.
Strawberry
Quick solution is to add 0 to the value
Nicholas Macharia
Changing offer_amount from VARCHAR to INT have worked. Thank you guys
lang-sql