Sql integer devision

This article is tagged with: Sql integer devision and mysql

SQL Integer devision

-- When performing division operations on integer values,
-- the results will always be integers and the results
-- may not always be what you expect.
SELECT 1 / 2; --> Result: 0
SELECT 1.0 / 2; --> Result: 0.5
SELECT CAST(1 AS REAL) / 2; --> Result: 0.5
SELECT 17 / 5; --> Result: 3
SELECT 17 % 5; --> Result: 2
-- Remember, these are integers and so the result will
-- be an integer and 1.0 is not an integer.

This article is tagged with: Sql integer devision and mysql