开发者

checking to ensure all values in a field are integers in MySQL

开发者 https://www.devze.com 2022-12-13 07:19 出处:网络
I have a column that is currently a floating-point number and I need to check if all the values in the column are i开发者_Go百科ntegers. What\'s the easiest way to do this?SELECT COUNT(*) FROM yourtab

I have a column that is currently a floating-point number and I need to check if all the values in the column are i开发者_Go百科ntegers. What's the easiest way to do this?


SELECT COUNT(*) FROM yourtable WHERE ceil(yourcolumn) != yourcolumn

If the count > 0 then there are non-integer values.


And to specifically find the records that are not integers...

SELECT * from yourtable WHERE col % 1 != 0;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号