#1873 Calculate Special Bonus
Notes
- Usage of
CASE
:
When multiple possibilities of conditions, we can use theCASE
statement
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
SELECT CustomerName, City, Country
FROM Customers
ORDER BY
(CASE
WHEN City IS NULL THEN Country
ELSE City
END);
- Usage of
NOT LIKE
withWildcards
in SQL:
In this case we are looking for words that do not start with a ‘M.’ Therefore we should use ‘M%’ with theNOT LIKE
to include them.
- Usage of remainders:
In this case we are looking for odd numbers, which means it has a remainder of 1 if divided by 2. There are several ways to indicate a remainder statement:MOD
statement:SELECT MOD(9, 2); // 1, odd number
x % y
SELECT MOD(employee_id, 2) != 0