From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Integer division

Integer division

- [Instructor] The SQL standard uses functions to perform integer division and the modula operation for the remainder of an integer division. MySQL uses non standard operators for this. So if we say select, and 47 divided by three, and execute, you'll see that the answer is 15 with a remainder, so it's 15 and 2/3. This is a real division operation. The result is a real number, with the fractional part represented as digits after the decimal point. This usage conforms to the standard. Now if I say div and in parentheses put the 47 comma three, and execute, you notice that I get an error. You have an error in your syntax. Check the manual, blah blah blah. So the div function is not supported by MySQL, and this is the SQL standard way to implement integer division. Instead, MySQL uses a nonstandard operator for this purpose. Like this, the word Div, D-I-V, is an operator in MySQL, and it's used between the numerator and the divisor, and when I execute this I get integer division. So the…

Contents