   16:12

# Integer division  Console
`SELECT 1/3 AS a, 5/3 AS b;`

Somebody (I suspect, they are users of MySQL or Oracle) expects the results in somewhat as

a      b
0.3333 1.6667
i.e. real number, the others -

a      b
0      2
i.e. the rounding to the nearest integer, whereas SQL Server gives

a       b
0    1

To resolve this bewilderment I shall tell, that operation "/" designates just the integer part of the result of dividing two integers  (namely, quotient) if both operands are integers. I.e. the separate designation for this operation is not supplied, and the symbol of "usual division" is used. If you wish to receive decimal number you need convert at least one operand to real data type explicitly (the first column) or implicitly (the second column):  Console
`SELECT CAST(1 AS DEC(12,4))/3 AS a, 5./3 AS b;`

a        b
0.333333    1.666666

Modulo operation is designated as "%" in SQL Server:  Console
`SELECT 1 % 3 AS a, 5 % 3 AS b;`

a    b
1    2

#### As for some other DBMS.

PostgreSQL behaves similarly SQL Server.

MySQL has a special operator DIV for obtaining a quotient:

`SELECT 1 DIV 3 AS a, 5 DIV 3 AS b;`

The remainder of division can be received also a la Pascal:

`SELECT 1 MOD 3 AS a, 5 MOD 3 AS b;`
though "standard" operator will also work:

`SELECT 1 % 3 AS a, 5 % 3 AS b;`

Oracle has not operator for getting quotient in general, so the division result

`SELECT 1/3 AS a, 5/3 AS b FROM dual;`

a    b
.333333333333333    1.66666666666667
you have to convert to needed integer, for example, so

`SELECT CEIL(1/3) AS a, CEIL(5/3) AS b FROM dual;`

a    b
1    2
or so

`SELECT FLOOR(1/3) AS a, FLOOR(5/3) AS b FROM dual;`

a    b
0

MOD function is used in Oracle for getting  remainder of division:

`SELECT MOD(1,3) AS a, MOD(5,3) AS b FROM dual;`

At last, if the divider equals zero  Console
`SELECT 1/0 AS a;`
MySQL returns NULL, whereas other DBMS considered here return divide by zero error.

Suggested exercises: 137  