Case has two formats. Simple case function and case search function.--Simple Case functionCase SexWhen ' 1 ' Then ' men 'When ' 2 ' then ' women 'Else ' other ' END--case search functioncase If sex = ' 1 ' Then ' man 'When sex = ' 2 ' Then ' women
Case has two formats. Simple case function and case search function.--Simple Case functionCase SexWhen ' 1 ' Then ' men 'When ' 2 ' then ' women 'Else ' other ' END--case search functioncase If sex = ' 1 ' Then ' man 'When sex = ' 2 ' Then ' women
The data SQL CASE expression is a generic conditional expression that resembles a if/else statement in another language.Case if condition then resultWhen condition then result.............[When ...][ELSE result]ENDThe case clause can be used where
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
Use LOCATE and case when... THEN... ELSE... END in mysql in combination,
In the previous project, you need to write an SQL statement to find out A survey details. Select answer A, Answer B, and answer C... f. The number of people in the answer is
Explain:1 SELECT 2 Case -------------If3 whenSex='1' Then 'male' -------------sex= ' 1 ', the return value ' male '4 whenSex='2' Then 'female' -------------sex= ' 2 ', the return value ' female '5
The great god says: In sql, you can use if else without casebelow to see, specifically why, did not figure out if there is a great God to know to provide the following information:MySQL can be used as an expression, or as a Process control statement
Easy to understand, directly on the example:SELECTCase-------------ifWhen sex= ' 1 ' Then ' Men '-------------sex= ' 1 ', then return value ' Male 'When sex= ' 2 ' Then ' Women '-------------sex= ' 2 ', then the return value ' female 'else 0---------
Explain:SELECTCase-------------IfWhen the sex= ' 1 ' then ' Male '-------------sex= ' 1 ', the return value ' male 'When the sex= ' 2 ' then ' female '-------------sex= ' 2 ', the return value ' female 'else 0 return ' other '-------------otherEnd---
Explain:SELECTCase-------------IfWhen the sex= ' 1 ' then ' Male '-------------sex= ' 1 ', the return value ' male 'When the sex= ' 2 ' then ' female '-------------sex= ' 2 ', the return value ' female 'else 0 return ' other '-------------otherEnd---
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.