Case has two formats. Simple Case functions and Case search functions.-- Simple Case FunctionCASE sexWHEN '1' THEN 'male'WHEN '2' THEN 'female'ELSE 'others' END-- Case search functionCase when sex = '1' THEN 'male'WHEN sex = '2' THEN
Conditional statementsdelimiter \\CREATE PROCEDURE proc_if ()BEGIN declare i int default 0; if i = 1 THEN SELECT 1; ELSEIF i = 2 THEN SELECT 2; ELSE SELECT 7; END IF;END\\delimiter ;Looping statementsWhile
Case has two formats. Simple case function and case search function. Simple case function Case sex when ' 1 ' THEN ' man ' when ' 2 ' THEN ' Else ' other ' end--case search function case when sex = ' 1 ' THEN ' man ' when sex = ' 2 ' THEN ' woman '
Copy Code code as follows:
--Simple Case function
Case Sex
When ' 1 ' THEN ' male '
When ' 2 ' THEN ' woman '
Else ' other ' end
--case search function
case when sex = ' 1 ' THEN ' man '
When sex = ' 2 ' THEN ' female '
Else
In our project development, we often encounter the requirements of multiple conditional fuzzy queries. There are two common solutions for this: one is to stitch the SQL string at the end of the program, construct the corresponding SQL string based
How to Use Case in SQL (Part 2)
Next
4. Conditional update.
For example, the following update conditions are available:
For employees with a salary of more than 5000, the salary is reduced by 10%.
Employees with salaries between 2000 and 4600
Case has two formats. Simple case function and case search function.--Simple case function Sexwhen ' 1 ' then ' Male ' when ' 2 ' then ' women ' else ' other ' end--case search function case when sex = ' 1 ' Then ' man ' when sex = ' 2 ' Then '
Case has two formats. Simple case function and case search function.--Simple case function Sexwhen ' 1 ' then ' Male ' when ' 2 ' then ' women ' else ' other ' end--case search function case when sex = ' 1 ' Then ' man ' when sex = ' 2 ' Then '
Case has two formats. Simple case function and case search function.--Simple Case functionCase SexWhen' 1 'then man ' when ' 2 ' then female ' else ' then ' man ' when sex = ' 2 ' then female ' end In both of these ways, the
Case has two formats. Simple case function and case search function.--Simple case function Sexwhen ' 1 ' then ' Male ' when ' 2 ' then ' women ' else ' other ' end--case search function case when sex = ' 1 ' Then ' man ' when sex = ' 2 ' Then '
Case has two formats. Simple case function and case search function.--Simple case function Sexwhen ' 1 ' then ' Male ' when ' 2 ' then ' women ' else ' other ' end--case search function case when sex = ' 1 ' Then ' man ' when sex = ' 2 ' Then '
4. Conditional update.
For example, the following update conditions are available:For employees with a salary of more than 5000, the salary is reduced by 10%.Employees with salaries between 2000 and 4600 increase by 15%You can easily choose to
There's always such a problem in the interview,The database is an essential issue.Today to share a database aspects of the face test!The topics are as follows:A data table AA is known, and the contents and format are as follows:Write a SQL to output
For the use of case, the simple case function is a simple case expression that uses an expression to determine the return value.Grammar:Case Search_expressionWhen Expression1 then RESULT1When Expression2 then RESULT2...When Expressionn then
Keyword: case
Case has two formats. Simple Case functions and Case search functions.
-- Simple Case Function
CASE sex
WHEN '1' THEN 'male'
WHEN '2' THEN 'female'
ELSE 'others' END
-- Case search function
Case when sex = '1' THEN 'male'
WHEN sex = '2'
Case has two formats. Simple case functions and case search functions.
-- Simple case Function Case Sex When '1' Then Male' When '2' Then Female' Else ' Miscellaneous' End -- Case search function Case When Sex = '1' Then
Next
4. Conditional update.
For example, the following update conditions are available:
For employees with a salary of more than 5000, the salary is reduced by 10%.
Employees with salaries between 2000 and 4600 increase by 15%
Case has two formats. Simple case functions and case search functions.
-- Simple case function case sex when '1' then' male 'when' 2' then' female 'else' other 'ends -- case search function case when sex = '1' then' male 'when sex = '2' then'
Use of case, simple case functionA simple case expression that uses an expression to determine the return value.
Grammar:
Case Search_expression
When Expression1 THEN RESULT1
When Expression2 THEN result2
...
When Expressionn THEN Resultn
Use of case, simple case functionA simple case expression that uses an expression to determine the return value.
Grammar:
Case Search_expression
When Expression1 THEN RESULT1
When Expression2 THEN result2
...
When Expressionn THEN Resultn
ELSE
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.