![mysql update query mysql update query](https://365datascience.com/resources/blog/2017-11-Installing-MySQL-43-1024x519.jpg)
We will create a function to calculate customer tier depending on the order_total Let’s see the use of IF-ELSE with the MySQL function. IF() function can be used independently with MySQL queries directly, however, MySQL IF ELSE is used as a statement as part of the stored procedures or functions. The SELECT query using the IF function is below: SELECT customer_name, IF(order_total>100,"yes","no") AS is_high_value So the problem statement can be – display high_value customer details for all Orders after Sept 1st, 2020. Suppose we want to have an additional display column, like – is_high_value customer, basis on order_total value > 100 Please refer to images of the tables with the test data as created above. (`order_id`,`customer_name`,`city`,`order_total`,`order_date`) VALUES We will use an Orders table as sample data for writing examples related to the IF ELSE functions in MySQL value_false: This is the String value that would get displayed when the condition evaluates to false.value_true: This is the String value which we would like to get displayed against the condition if it’s evaluated to true.
![mysql update query mysql update query](https://downloads.guru/i/win10/MySQL-Workbench_main_window_11868_650x200.jpg)
Here, we can write a condition if column_name > 100 For example: Checking whether the value against the column is > 100. It can involve single or multiple columns. condition: It is the conditional statement that we want to evaluate.Let’s try to understand the syntax in detail (here we are using SELECT query with IF function) Syntax: SELECT IF(condition, value_true, value_false) AS Using COUNT With IF To Group Against Ranges.