I have a table that contains float values.
+ id | value |
+--------|---------|
+ 1 | 19.22 |
+ 2 | 32.333 |
+ 3 | 1.
Try this:
select value, LEN(value) - CHARINDEX('.', value) as DecimalCount from Table
where LEN(value) - CHARINDEX('.', value) > 2
NOTE: I'm not using mySQL, I have MSSQL. let me know if this works for you - just noticed you asked for a mySQL solution.
UPDATE: Felt bad for answering for the wrong platform. A bit of research got me this for mySQL:
select * from Table
where LENGTH(SUBSTRING_INDEX(value, '.', -1)) > 2
Cast the value
column as a varchar
and use string comparison.
This worked for me:
SELECT *
FROM table
WHERE column <> ROUND (column,2)
or:
SELECT *
FROM table
WHERE column <> CAST (column AS DECIMAL(36,2))
SELECT * FROM table t WHERE floor(t.columnname)!=t.columnname
This regex (MySQL 5.0+) worked for me, based on the data you provided:
SELECT t.*
FROM YOUR_TABLE t
WHERE t.`value` REGEXP '[0-9]+.[0-9][0-9][0-9]+'
Reference:
This worked for me
SELECT *
FROM `table`
WHERE LENGTH(SUBSTR(`value`,INSTR(`value`,"."))) >3
Counting the decimal .01 is 3, .011 is 4