Reference: http://database.51cto.com/art/201005/201651.htm
Http://www.lai18.com/content/1693593.html
Directly on the example, the following is the processing of the field cost divided by 1000, leaving two decimal places
Cast (SUM (a.costs)/1000 as Decimal (32,2))
The cast () function is a conversion function, which is an expression that includes the source value and the target data type separated by the AS keyword.
1) Convert the string ' 123 ' to int integer type:
Select CAST (' 123 ' as int) #out: 123
2) Neither the CAST () function nor the CONVERT () function can perform rounding or truncation operations:
SELECT CAST (' 123.4 ' as int)
Since 123.4 cannot be represented by an int data type, a call to this function will result in an error.
decimal (m,d) is a data type with the parameter M as the numeric precision, the precision being the total number of digits (the sum of the decimal and integer digits), and D being the number of decimal digits to keep.
Note: 1) parameter m<65 is the total number, d<30 and d<m are decimal digits.
2) The maximum possible range of decimal values is the same as a double, but the valid range of values is determined by the values of M and D. If M is changed and the D is fixed, the range of values will be larger with M.
Cast (), Decimal (m,d)--sql Preserve decimal operations on query fields