This one is database related problem and pretty easy. Click here to see the problem on LeetCode. Read the description and try to understand the problem.
Note: I assumed that you have basic knowledge of SQL language.
The actual problem is, we have to retrieve data from the database with some condition. We have to write a query so that we can get all the cinema from the cinema database. But the conditions are, the cinema description can’t be boring, and id number must be odd. And of course, the table must be ordered by the rating (high to low).
In the example table, we will see all the columns’ names.
SQL code is like the English language. Let’s see the solution first.
SELECT * FROM cinema WHERE id % 2 != 0 AND description != 'boring' ORDER BY rating DESC
The solution is almost self-explanatory. Here we select all the columns and rows from the cinema table using the * sign. But using the “WHERE” keyword, we verified our condition. And the ‘AND‘ keyword verified that both conditions must be true. If you know about Logical Operator, you already know how ‘AND‘ works.
After checking conditions, we organize our table in a descending order based on rating using the ‘ORDER BY‘ and ‘DESC‘ keyword.
So, this SQL command will retrieve all the columns and rows from the cinema table if and only both condition is true. Column names cannot be mistaken.
This is the solution to this problem. I hope you got the idea.
Happy Coding 🙂
Keep Practicing 🙂