IKH

Case Statements – I

You may have encountered if-else and case statements in some programming languages. Now, suppose you are in school and have to follow a set time-table, according to which you need to bring the textbooks of certain subjects on certain days to class. Consider the following time-table:

  • Monday: English and Hindi.
  • Tuesday: English and Maths.
  • Wednesday: Science and Social Science.
  • Thursday: Maths and Social Science.
  • Friday: Hindi and Science.

This is a basic example where you can determine the subjects that you would be studying in class on certain days by just looking at the list. However, the data around us is enormous and complex. There may be several conditions that you may need to set and many actions to be performed according to each of these conditions.

As you learnt in the video, the syntax for writing a case statement is as follows:

So, now that you know the syntax for writing a case statement, in the next video, Shreyas will walk you through a practical example where you will classify orders based on the amount of profit or loss incurred.

Now, answer the questions given below regarding the basic functions of a case statement in MySQL.

Now, solve the coding question given below to understand the importance of case statements in solving actual business problems. You will realise how easy it is to classify groups of values based on some given conditions. Such classifications help companies take important business decisions.

In the next segment, you will learn how case statements can be applied with other SQL concepts to solve complex questions.

Report an error