What does this asterisk(*) mean?
select
employee_id,
salary * (employee_id % 2) * (name not like "M%") as bonus
from Employees order by employee_id;
What does this asterisk(*) mean?
select
employee_id,
salary * (employee_id % 2) * (name not like "M%") as bonus
from Employees order by employee_id;
2
Answers
It’s multiplication.
when data is
result will be
here,
(name not like "M%")
is boolean. mysql-booleanThe asterix is actually the simplest part of the expression. It is the multiplication operator.
salary * (employee_id % 2) * (name not like "M%")
multiplies the three numbers.(employee_id % 2)
is the modulo (remainder) of employee_id divided by 2. This means it is 0 for even IDs and 1 for odd IDs.(name not like "M%")
is a boolean expression (and the quotes should better be single quotes for standard-compliancy). We want a number here in order to apply our multiplication. MySQL converts booleans according to the rule TRUE = 1, FALSE = 0.The result of the whole expression is hence:
A more readable way to write the query would hence be: