Case clause, which can be logically judged after a select.
Two forms: judging equality, judging unequal
The syntax for judging equality:
Case Column Name
When ... then ...
When ... then ...
else ...
End as column alias
One: Create a new table and insert the initial data.
--Check the entire table .Select* fromSdetail--Insert initial data insert into Sdetail (Sname,sscore,sgender) VALUES ('Andy Lau', About,0) insert into Sdetail (Sname,sscore,sgender) VALUES ('Louis Koo', -,0) insert into Sdetail (Sname,sscore,sgender) VALUES ('-Mei', -,1) insert INTO Sdetail E (sname,sscore,sgender) VALUES ('Liang', +,0) insert into Sdetail (Sname,sscore,sgender) VALUES ('Wang Leehom', About,0) insert into Sdetail (Sname,sscore,sgender) VALUES ('Liu Yifei', the,1)View Code
Case clauses determine equality
- - Two forms of case syntax Select * 0' male ' 1 ' female ' as ' Sex ' from Sdetail
View Code
Execution Result:
Second, Judgment unequal (range)
A logical expression that contains column names then ...
When ... then ...
else ...
End as column alias
- case judgment Unequal (range)Select * , case when sscore> Pass 'else' less than grid 'as' ' from Sdetail
View Code
Execution Result:
Two forms of case clauses in SQL