select with case in mysql

Solutions on MaxInterview for select with case in mysql by the best coders in the world

showing results for - "select with case in mysql"
Matthias
12 Jan 2021
1SELECT CASE lower(col1)
2	WHEN 'agree' THEN 'Ok'
3	WHEN 'disagree' THEN 'Ko'
4    ELSE
5        CASE 
6            WHEN col2 = 1 THEN 'Ko'
7            ELSE 'Maybe'
8        END
9END AS my_result
10FROM table_name;
Federico
27 Jan 2017
1mysql> SELECT CASE  WHEN 2>3 THEN 'this is true' ELSE 'this is false' END; 
2+-------------------------------------------------------------+
3| CASE  WHEN 2>3 THEN 'this is true' ELSE 'this is false' END |
4+-------------------------------------------------------------+
5| this is false                                               | 
6+-------------------------------------------------------------+
Luis
08 May 2020
1-- LABEL MOVIE LENGTH 
2select title, length,
3CASE 
4	 when length < 50 then 'very short film'
5     when length < 90 then 'short film'
6     when length < 120 then 'medium length film'
7     when length > 120 then 'long film'
8     else 'unknown length'
9END -- AS film_length
10from film;
11
12-- SAME AS ABOVE BUT ON A CUSTOM NAMED COLUMN
13select title, length,
14CASE 
15	 when length < 50 then 'very short film'
16     when length < 90 then 'short film'
17     when length < 120 then 'medium length film'
18     when length > 120 then 'long film'
19     else 'unknown length'
20END  AS film_length
21from film;
22
23-- RESULT
24+-----------------------------+--------+--------------------+
25| title                       | length | film_length        |
26+-----------------------------+--------+--------------------+
27| ACADEMY DINOSAUR            |     86 | short film         |
28| ACE GOLDFINGER              |     48 | very short film    |
29| ADAPTATION HOLES            |     50 | short film         |
30| AFFAIR PREJUDICE            |    117 | medium length film |
31| AFRICAN EGG                 |    130 | long film          |
32| AGENT TRUMAN                |    169 | long film          |
33| AIRPLANE SIERRA             |     62 | short film         |
34| AIRPORT POLLOCK             |     54 | short film         |
35| ALABAMA DEVIL               |    114 | medium length film |
36| ALADDIN CALENDAR            |     63 | short film         |
37| ALAMO VIDEOTAPE             |    126 | long film          |
38| ALASKA PHANTOM              |    136 | long film          |
39| ALI FOREVER                 |    150 | long film          |
40| ALICE FANTASIA              |     94 | medium length film |
41| ALIEN CENTER                |     46 | very short film    |
42
Jock
28 Mar 2018
1SELECT 
2t2.company_name,
3t2.expose_new,
4t2.expose_used,
5t1.title,
6t1.status,
7 CASE status
8   when 'New' and t2.expose_new = 1 then 1
9   when 'New' and t2.expose_new = 2 then 2
10   when 'New' and t2.expose_new = 3 then 3
11   when 'Used' and t2.expose_used = 1 then 1
12   when 'Used' and t2.expose_used = 2 then 2
13   when 'Used' and t2.expose_used = 3 then 3
14END as expose
15FROM `products` t1
16join manufacturers t2 on t2.id = t1.seller
17where t1.seller = 4238
Lea
28 Jun 2016
1
2  SELECT 
3CASE
4    WHEN Quantity > 30 
5  THEN "The quantity is greater than 30"
6    WHEN Quantity = 
7  30 THEN "The quantity is 30"
8    ELSE "The quantity is 
9  under 30"
10END
11FROM OrderDetails; 
queries leading to this page
case if mysqlmysql select with casewhere case in mysqlmysql case on selectcase statement default mysqlmysql case statement with selectswitch syntax mysqlwhere case when mysqlswitc casa mysqlmysql if or caseuse case statement in mysqlcase myswlsql query switch case mysql add case statements togethercase 2c when 2c then mysqlsql switch column positioncase when if mysqlysql casemysql case query for where conditioncase statement in mysqlis case is available in mysqlmysql server case whenthen end in mysqlmysql case when order bymysql select case replacecase in mysqlcase mysql how to usemysql query switch case wherewhere in case mysqlhow to use case in mysqlmysql casewhenmy sql case whenselect case mysqlmysql 2bcasecase structure mysqlcase as mysqlcan we write case statement in where clause in mysqlcase en mysql clausecase expression in mysqlcase statements in mysqlcase if then mysqlmysql no support case cinditionmariadb case when null thencase statement in mysql case in where mysql functionwhen case in mysql querywhere case mysqlmysql query in casescase in mysql 3bmariadb switch casemysql case statement with andmysql if and casecase mysq c3 a7execute command in case syjntax of mysqlmysql switch casesql case columncase whe is 1 mysqlmysql case with 3c 3e mysql use case whenwhen case mysql examplemysql switch case in selectmysql where casemysql query with switch casemysql whenmysql switch case in functionmysql case when in where clausemysql function case switchmysql case andmysql case selectcase statement in mysql examplewhen condition in mysqlcase default in mysqlmariadb switch case examplewhen case with or mysqlmariadb when casemysql case statement in metqbasecase in where clause in mysqlhow do you perform operations in case statement in mysqlcase with query in mysqlcase and end mysqlselect with case mysqlcase mysqlselect case mysql when not in mysql query switch casehow use case in mysqlcase whent then in mysqlswitch or use mysqlmariadb case 3d 3d switch mysqlmysql case in selectmysql proper casecase my sqlmysql query case whenswitch statement mysqlwhen case sql mysqlcase statement in procedure mysqlcase value in case statement sql what is usedselect mysql whenor in case in mysqlmysql case with ormysql select case when elsecase statement in where clause mysqlselect case when mysqlcase statement mysql operatorscase in mysqlcase functioncase whern in mysqluse switch case statement in mysqlmysql write select in case statementmysql case ehrn endand in case mysqlmysql when case 3d valuecase then in mysqlcase when query in mysqlmysql case fromcase when in where clause mariadbis mysql completely case inmysql case in case exampleswitch case in sqlcase when in myslqhow to use case 2b mysqlthen mysqlmysql case when thencase when select columnthen and mysqlswitch case mysql with set variablecase column mysqlmysql case with andmysql select in caseselect query in when case statement in mysqlcase when select mysqlswitch case in mysqlmysql table casemysql case when else ifmysql case inside casemysql case as in selectmariadb casemysql case structuremysql case select statementmysql case tablecase statement in mysql select queryswitch case in select mysqlmysql case when orcase when in muysaqlmysql case for edge browserswitch sqlmysql from where case mysql case in where clausemysql case in wherecase en mysqlcase mysql selectmysql case whencase if when mysqlswitch case sql columnmysql case statementmysql case when queryalter table switchand case and mysqlcase statement mysqlcase select mysqladd case in mysqluse case with where mysqlcase condition in mysqlmysql when thencase inside case in mysqluse case starment in mysqlswitch case example in mysqlcase when mysqmysql can i case when a table 3fand case and mysql whenas and then in mysqlmysql switchmysql case statement equal tocase on column in mysqlmysql case statements worksheetwhen case in mysqlmysql where case whencase when mysql syntaxcase if in mysqlswitch in mysqlcase in my sqlmysql show the case off the where clauseswtich in mysqlmysql select casemysql select case if then as columnmysql case when with or conditionmariadb case switchswitch mysql querycase when end as mysqlmysql case if eseifcase syntax for mysqlhow to switchthe values in a column in sqlmysql where case conditionset into case condition mysqlphpmyadmin case returnmysql casecase in mysql selectcases in mysqlselect case php mysqlmysql case when evalueates allcase then mysqlmysql case ifcase when with where mysqlswitch case my sqlmysql case switchapply manipulation on case column sqlselect query inside case statement in mysqlselect case when mysqlmysql case from tableselect case when string mysqlwhat is select case in mysqlmysql case then in select queryhow to use case statement in mysqlmysql case stamysql switch case insertmysql case syntaxmysql case when in selectcase sample mysqlwhen mysqlcase in mysql querycase function inswitch statements mysql selectswicth case mysqlselect case where mysqlmysql case 28 29use case in mysql where clausecase in result mysqlmysql case d 25mysql case datecase when then in mysqkwhen case or mysqlmysql switch statementhow to change column value using case in sqlmysql case thenmysql swtich case syntacsql switch statementmysql query case when only using oneselect column on case in sqlwhat is the case statement syntax in mariadbmariadb switch databaseswitch signs int sqlmysql case operatormysql select whenmysql sql casemysql using case in where clausemysql when casecase column mysql end ascase for where mysqlsql change column value casetable switch mysqlselect case in mysqlswitch casein sql mysqlmysql case example tutorialmysql case setncencorrect case mysqlhow to switch from mariadb to mysqlswitch uer mysqlcase when in mysql querycase in mariadbhow can use switch in mysqlmysql switch case defaultmysql case statement inside functionmysql select case elseselect if case mysqlmysql case keywordquery in case statement mysqlmysql case when syntaxmysql can you start with a case statementhwo to igonre case in mysqlswitch case mysql 5cswitch in mysql querymysql select in case statementmysql case calculossql case statement mysqlmysql case statement in select clauseswitch case mysqlmy sql syntax of casemysql case mysql case without selectmysql select case statementcase no myusqlselect swtich case mysqlswitch mariadbselect case statement in mysqlmysql case statement insertmysql 2b case when 2b defaultmysql query select case whencase when else if mysqlcase when en sql mysqlmariadb case statementselect column with case statement in sqlusing case in mysqlmysql case when and orcase use in mysqlcase with column values in mysqlcase en mysql definicionmysql case phphow to use case in mysql select querysql switchhow to write case in mysqlmariadb case when exampleswithc case mysqlcase syntax in mysqlmysql case when or conditionmysql query sentence casemysql workbench casecase in mysql with andmysql thenmysql case when in case whenhow case works in mysqhow to use use case in mysqlmysql case insensitvemysql function case when case statement in where clause in mysqlcase in where clause in mysql sqlquery case mysqlmysql select case then column valuemariadb case whenor in case statement mysqlget from to in mysql query case thenmysql select case when betweenmysql case with conditions betweenselect case when in mysqlcase mysql querymysql case when havingmy sql casemysql when then elseswitch case mysql valuesmysql ceseusing case statemnt in mysqlswitch columns in sqlmysql case asselect statement in a case statement mysqlunion case mysqlmysql case when then endsql switch casecase when condition in mysqlcase when mariadbmysql case insensivite likecase when in mysqlcase site 3amysql comthen in mysqlmysql case when with andselect inside a case statement mysqlcase when trong mysqlswitch case in mysql select queryany case in mysqlmysql case statement keywordsswitch case in myswlmysql 2b switchcase in where clause mysqlmysql case in select statementswitch statement in mysql procedurecase when select mysqmariadb case when thencase when in select statement mysqlwhen case mysqlmariadb case expressionsselect case statement mysqlselect with case in mysqlmysql case with variablecase when then mysqlmysql case when casecase when or when mysqlmysql case when andmysql case when new valuemysql case when in where conditioncase when in select mysqlmysql case case defaultmysql function switch casemysql case stop breakmysql swtich casemysql query case ifmysql switch case in procedurecase mariadbmysql case when selectmysql case elsemysql case else upperw3 schools mysql casmysql select case whenmysql case functionproper case mysqlcase statement mysql syntaxcase when is in mysqlmysql switch case textchekc qual to in swithc case in mysqlcase when then in mysqlmysql case querysql switch to table when mysqlcase staemnt in mysqlcase to execute commands sqlwhen in mysqlcase when with and mysqlmysql select switchmysql where case statement exampleif case in mysqlmysql case funcase when mysqlmysql case namecase statement syntax mysqlcase when syntax mysqlcase im mysqlbetween with when case select mysqlmysql case when field and fielsmysql case examplemysql seelect whencase then with and or in mysqlcase in mysq 3bcase in select statement in mysqlsql switch case statementmysql case when elsecase no mysqlselect with case in mysql