CAST DECIMAL to INT

后端 未结 10 2300
攒了一身酷
攒了一身酷 2020-12-13 01:49

I\'m trying to do this:

SELECT CAST(columnName AS INT), moreColumns, etc
FROM myTable
WHERE ...

I\'ve looked at the help FAQs here: http://

相关标签:
10条回答
  • 2020-12-13 02:14

    1 cent: no space b/w CAST and (expression). i.e., CAST(columnName AS SIGNED).

    0 讨论(0)
  • 2020-12-13 02:15

    There's also ROUND() if your numbers don't necessarily always end with .00. ROUND(20.6) will give 21, and ROUND(20.4) will give 20.

    0 讨论(0)
  • 2020-12-13 02:16

    There is an important difference between floor() and DIV 1. For negative numbers, they behave differently. DIV 1 returns the integer part (as cast as signed does), while floor(x) returns "the largest integer value not greater than x" (from the manual). So : select floor(-1.1) results in -2, while select -1.1 div 1 results in -1

    0 讨论(0)
  • 2020-12-13 02:17

    Try cast (columnName as unsigned)

    unsigned is positive value only

    If you want to include negative value, then cast (columnName as signed),
    The difference between sign (negative include) and unsigned (twice the size of sign, but non-negative)

    0 讨论(0)
提交回复
热议问题