Conditional statement in SQL
We have an if condition in programming sector to handle the conditional operation. Like that in SQL conditional operation done by using CASE statement. A sample example of CASE statement in sql is given below,
syntax,
SELECT CASE ("column_name")
WHEN "value1" THEN "result1"WHEN "value2" THEN "result2"
...
[ELSE "resultN"]
END
FROM "table_name";
eg:
SELECT Store_Name, CASE Store_Name
WHEN 'Los Angeles' THEN Sales * 2
WHEN 'San Diego' THEN Sales * 1.5
ELSE Sales
END
"New Sales",
Txn_Date
FROM Store_Information;
WHEN 'Los Angeles' THEN Sales * 2
WHEN 'San Diego' THEN Sales * 1.5
ELSE Sales
END
"New Sales",
Txn_Date
FROM Store_Information;
By Varun K.R
Comments
Post a Comment