CAST to DECIMAL in MySQL

后端 未结 5 573
甜味超标
甜味超标 2020-12-23 12:08

I am trying to cast to Decimal in MySQL like this:

CAST((COUNT(*) * 1.5) AS DECIMAL(2))

I\'m trying to convert the number of rows in a tabl

5条回答
  •  一向
    一向 (楼主)
    2020-12-23 12:21

    From MySQL docs: Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC:

    In standard SQL, the syntax DECIMAL(M) is equivalent to DECIMAL(M,0)

    So, you are converting to a number with 2 integer digits and 0 decimal digits. Try this instead:

    CAST((COUNT(*) * 1.5) AS DECIMAL(12,2)) 
    

提交回复
热议问题