Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

MySQL Introduction

MySQL Setup

MySQL Operators

MySQL Basic Works

MySQL Create Table

MySQL insert and get values

MySQL Condition

MySQL GROUP BY

MySQL Case

MySQL sorting and calculate avg,sum,count

MySQL Update

MySQL Time

MySQL String

MySQL Rollback & Commit

MySQL Join and Concatenate

MySQL Index

MySQL Date

MySQL View

MYSQL With Python

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

SQL case

What is case?

The working of case is the same as if else statement. This statement goes through conditions and if the condition gets matched then it returns the value and stop running.
If any value doesn't get matched then it will return else statement. If there is no else condition then it will return NULL

Syntax:
SELECT columns_name(Those column names where we want to set condition),
CASE
    WHEN condition THEN print_value( what it should print if condition is true)
    WHEN condition THEN print_value(what it should print if condition is true)
ELSE print_value(what it should print if condition is true)
END AS column_name(write new column name to print values if get matched)
FROM Table_name;

Example:
SELECT Books, Price,
CASE
   WHEN Price > 150 THEN 'The price is greater than 150'
   WHEN Price = 300 THEN 'The Price is 300'
   ELSE 'The Price is no range'
END AS price_details
FROM books_store;

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.