case when then end

The execution of the change statement is : take case The value of the following expression is the same as that of each when Compare values in clause , If the two are equal , Then return to then The value of the expression after , Then jump out case language sentence , Otherwise return to else The value of the expression in clause .else Clause is optional . When case There is no meal in the sentence else When clause , If all comparisons fail ,case Statement will return NULL.

【 example 】 From the data sheet stud_info in , selection stud_id,grade, If grade by ' male ' The output ’M‘, If ’ Woman ‘ Output 'F'.

SELECT stud_id,sex=CASE gender WHEN ’ male ‘ THEN 'M' WHEN ' Woman ' THEN ’F‘ END FROM stud_info

mysql case when then else end More related articles on the usage of

  1. mysql CASE WHEN The basis and multiple uses of

    CASE Evaluates the condition list and returns one of several possible result expressions . CASE There are two formats : Simple CASE Function compares an expression with a set of simple expressions to determine the result . CASE The search function evaluates a set of Boolean expressions to determine the result .  two ...

  2. mysql Export table structure and table data mysqldump usage

    mysql Export table structure and table data mysqldump usage The specific usage of the command line is as follows :   mysqldump -u User name -p password -d Database name Table name > Script name ; Export the entire database structure and data mysq ...

  3. mysql Introduction to four usages of fuzzy query in

    Let's introduce mysql Four uses of fuzzy query in : 1,%: Express arbitrarily 0 Characters or more . Matches characters of any type and length , In some cases, it's Chinese , Please use two percent signs (%%) Express .  such as SELECT * FROM [user] ...

  4. Mysql Learning notes —concat as well as group_concat Usage of ( Reprint )

    The examples used in this article are in the following database tables tt2 perform : One .concat() function 1. function : Concatenate multiple strings into a single string . 2. grammar :concat(str1, str2,...) The return result is the word generated by the connection parameter ...

  5. Positive rate mysql CASE UNION ALL

    Positive rate mysql CASE UNION ALL SELECT t.*,t.type_0/all_ FROM ( SELECT FROM_UNIXTIME(create_time,'%Y-%m-%d ...

  6. MySQL common 8 Kind of SQL Incorrect usage

    MySQL common 8 Kind of SQL Incorrect usage Preface MySQL stay 2016 It still maintained a strong growth trend of database popularity in 2007 . More and more customers are building their applications in MySQL Above the database , Even from Oracle Migrate to MySQL come up . But also ...

  7. mysql function GROUP_CONCAT(temp.amount SEPARATOR ',') Usage of

    mysql function GROUP_CONCAT(temp.amount SEPARATOR ',') Usage of Use scenarios : for example : Want to check the user's favorite purchases , You need to use group_concat( word ...

  8. Let's introduce mysql Four uses of fuzzy query in :

    Let's introduce mysql Four uses of fuzzy query in : 1,%: Express arbitrarily 0 Characters or more . Matches characters of any type and length , In some cases, it's Chinese , Please use two percent signs (%%) Express . such as SELECT * FROM [user] ...

  9. MySql in case when then else end Usage of

    explain : SELECT                case                   ------------- If     when sex='1' then ' male ' ---------- ...

Random recommendation

  1. Ubuntu 14.04 MySQL Sync

    master server :192.168.2.212 From the server :192.168.2.211   master server (192.168.2.212): Come first /etc/mysql/my.cnf Next take bind-address 127 ...

  2. Git Basic interaction flow chart

  3. poj 1004 Financial Management

    Average , I remember I was in Hangdian before oj I've done a problem of average number on , As a result, the title is in English , I'm so confused #include <stdio.h> int main() { ; double num; int ...

  4. Web Application workflow summary

    understand Web The working process of the application benefits Web Better understanding when testing ,Web The process of application work is divided into the following 5 A step : 1. The user is in Web Enter a... In the browser Web Address . Select a hyperlink or click a button 2. Web The browser takes the user's actions ...

  5. Reprint [WampServer Use multi port access under ]

    author : Han zichi Link to the original text :http://www.cnblogs.com/zichi/p/4589142.html Be careful :www and www2 All need installation services : stay C:\wamp\bin\apache\Apa ...

  6. redis Use get key Chinese becomes hexadecimal code

    redis-cli Followed by --raw Solve the problem of Chinese display redis-cli -h 127.0.0.1 -p port -a password   --raw No --raw Parameters : redis-cli -h &g ...

  7. a sheet JVM Related mind maps (4.4M)

    The building owner studies JVM Summary of knowledge points , String them up with mind maps , Consider the past you shall know the future , It contains class loaders , Memory layout ,GC( On the right side ). Most of all GC Content. . There are mistakes in the content , Also please correct me . Big picture address

  8. OSI Network architecture

    To interconnect a system developed under one network structure with a system developed under another network structure , To achieve a higher level of application , Make it possible to communicate between heterogeneous computers , Facilitate the standardization of network structure , International Organization for Standardization (ISO) On 1983 The basic parameters of Open Systems Interconnection were formed in ...

  9. Use Rectangle+ImageBrush Instead of Image, Solve the problem of blurred pictures

    <Rectangle Margin="0" Stroke="Black" HorizontalAlignment="Right" Wi ...

  10. HDU 5640 King&#39;s Cake GCD

    King's Cake Topic linking : http://acm.hdu.edu.cn/showproblem.php?pid=5640 Description It is the king's birthd ...