Use cast as decimal
.
Change:
SELECT Sum(price * qty) AS tot_sub,
( Sum(( price + tax ) * qty) ) AS tot
FROM products
WHERE order_id = 123
To:
SELECT Sum(price * qty) AS tot_sub,
Sum( ( cast( price as decimal(10,2) )
+ cast( tax as decimal(10,2) ) ) * qty ) AS tot
FROM products
WHERE order_id = 123
Refer to:
- MySQL: CAST(expr AS type)
- The CAST() function takes an expression of any type and produces a result value of a specified type.