Your company hired an intern database engineer, who immediately started updating the data in the system. Unfortunately, he hasn't fully grasped the concept of NULL values yet and he performed some incorrect inserts and updates to the departments table, which has the following structure: id: the unique department ID; name: the name of the department; description: the description of the department. Now you have a table where the description column holds values such as ' NULL ', NULL, 'nil' and ' - '. You need to find out exactly how many records in the table should have NULL in the description column, regardless of whether the intern input the value correctly or not. He used the following values to indicate NULL: NULL: just a regular NULL value; 'NULL': NULL as a case insensitive (i.e. NuLl is also OK) string with an arbitrary number of spaces at the beginning and at the end; 'nil': nil as a case insensitive (i.e. niL is also OK) string with an arbitrary number of spaces at the beginning and at the end; '-': a single dash with an arbitrary number of spaces at the beginning and at the end. Given the departments table, compose the resulting table with the single column number_of_nulls containing a single value: the number of rows in the departments table that are supposed to have NULL in the description. |
code>>
/*Please add ; after each select statement*/
CREATE PROCEDURE nullIntern()
BEGIN
SELECT COUNT(id) number_of_nulls FROM departments
WHERE description IS NULL
OR UPPER(TRIM(description)) = 'NULL'
OR UPPER(TRIM(description)) = 'NIL'
OR TRIM(description) = '-';
END
'알고리즘 > codefightsDB' 카테고리의 다른 글
24>websiteHacking (0) | 2019.03.25 |
---|---|
23>marketReport (0) | 2019.03.25 |
22>soccerPlayers (0) | 2019.03.25 |
21>travelDiary (0) | 2019.03.25 |
20>movieDirectors (0) | 2019.03.25 |