简体   繁体   中英

MYSQL column type for only positive number bigger or equal to 0?

I want to ask to what i must se my MYSQL column type so always the value there will be 0 or greater and never like number -15 .

I need it for one my PHP script which is calculating differences and i don't want to get a result in my column smaller then 0.

I want when it calculate in case 20 - 30 to set in my MYSQL column 0 not -10 if you get what i want.

So is there any chance this will be done with MySQL comumn type?

Thanks in advance!

You can use UNSIGNED integer types for your columns for holding only positive values, but when you're doing calculations in SQL I'm pretty sure you're always going to end up with a negative number if you subtract a large number from a smaller one. Even if you somehow forced mySQL to use an unsigned INT internally you would not end up with zero, you would end up with integer underflow and get a huge positive number instead.

Apply logic operations . If the number is less than zero, then replace it with zero.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM