3.3. Four-Function Arithmetic

SQL is weaker than a pocket calculator. The dyadic arithmetic operators +, –, *, and / stand for addition, subtraction, multiplication, and division, respectively. The multiplication and division operators are of equal precedence and are performed before the dyadic plus and minus operators.

In algebra and in some programming languages, the precedence of arithmetic operators is more restricted. They use the “My Dear Aunt Sally” rule; that is, multiplication is done before division, which is done before addition, which is done before subtraction. This practice can lead to subtle errors.

For example, consider (largenum + largenum – largenum), where largenum is the maximum value that can be represented in its numeric ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.