From the course: MySQL Essential Training
Unlock this course with a free trial
Join today to access over 23,400 courses taught by industry experts.
Arithmetic operators - MySQL Tutorial
From the course: MySQL Essential Training
Arithmetic operators
- [Bill] Hi, I'm Bill Weinman. MySQL provides a complete set of arithmetic operators. So if I say SELECT 5 + 3, I get a result that says 8. If I say SELECT 5 - 3, I get 2. If I say 5 * 3, I get 15. If I say 5 / 3, I get 1 and a fraction. So this is a floating point division. And you notice that I get the real number, 1.6667. It's rounded off. Obviously, the sixes go on forever. But if I wanted an integer result, I can say 5 DIV 3, and that'll give me 1. But we know that this has a remainder. So what's the remainder? I get the remainder with the modular operator, MOD. And the remainder is 2. When I divide 3 into 5, I get one 3 but a remainder of 2, right? The percent symbol may also be used for modular. So 5 % 3 gives me the same result. And if we say / 0, entirely by accident, of course, the result comes up null rather than giving us an error. The arithmetic operators are both intuitive and functionally complete.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.