fullstack_webdev

Code and notes from Full stack web developer path, LinkedIn Learning.

View on GitHub

6. Numbers

06_01 Numeric Types

06_02 Finding type of a value

SELECT TYPEOF(1 + 1); -- Returns integer

SELECT TYPEOF(1 + 1.0); -- Returns real

SELECT TYPEOF('panda'); -- Returns text

SELECT TYPEOF('panda' + 'koala'); -- Returns integer

06_03 Integer Division

-- Returns 0 since int division
SELECT 1/2;

-- Returns 0.5
SELECT 1.0/2;

-- Returns 0.5
SELECT CAST(1 AS REAL)/2;

-- 3
SELECT 17/5;

-- 3 and 2, int division and modulo division
SELECT 17/5, 17%5;

06_04 Rounding Numbers

-- Returns the number as it is
SELECT 2.55555;

-- Rounds to next INT and returns 3
SELECT ROUND(2.55555);

-- Returns 2.556
SELECT ROUND(2.55555,3);

-- 3
SELECT ROUND(2.55555,0);