Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql case when on date

SELECT
  id,
  CASE
    WHEN date_activated > '2011-11-23 18:30:00' THEN 'after'
    WHEN date_activated > '2010-01-20 00:00:00' THEN 'before'
    ELSE 'not yet'
  END AS date_note
FROM table1;
Comment

mysql case when or

SELECT
    CASE 
        WHEN
            column IS NULL OR another_column = 1
        THEN
            'yes' 
        ELSE
            'no' 
    END AS 'MyData'
FROM
    table_name;
Comment

mysql switch case

SELECT CASE lower(col1)
	WHEN 'agree' THEN 'Ok'
	WHEN 'disagree' THEN 'Ko'
    ELSE
        CASE 
            WHEN col2 = 1 THEN 'Ko'
            ELSE 'Maybe'
        END
END AS my_result
FROM table_name;
Comment

mysql case

 select 
(CASE
	WHEN (market_cap < 300000000) THEN 'micro'
	WHEN (market_cap < 2000000000) THEN 'small'
	WHEN (market_cap < 10000000000) THEN 'mid'
	WHEN (market_cap < 50000000000) THEN 'large'
ELSE 'mega'
END) AS `cap_type`
from companies;
Comment

mysql case when in select

SELECT CASE col1
	WHEN 'agree' THEN 'Ok'
	WHEN 'disagree' THEN 'Ko'
    ELSE
        CASE 
            WHEN col2 >= 1 THEN 'Ko'
            ELSE 'Maybe'
        END
END AS my_result
FROM table_name;
Comment

mysql switch case

SELECT 
t2.company_name,
t2.expose_new,
t2.expose_used,
t1.title,
t1.status,
 CASE status
   when 'New' and t2.expose_new = 1 then 1
   when 'New' and t2.expose_new = 2 then 2
   when 'New' and t2.expose_new = 3 then 3
   when 'Used' and t2.expose_used = 1 then 1
   when 'Used' and t2.expose_used = 2 then 2
   when 'Used' and t2.expose_used = 3 then 3
END as expose
FROM `products` t1
join manufacturers t2 on t2.id = t1.seller
where t1.seller = 4238
Comment

mysql switch case

mysql> SELECT CASE  WHEN 2>3 THEN 'this is true' ELSE 'this is false' END; 
+-------------------------------------------------------------+
| CASE  WHEN 2>3 THEN 'this is true' ELSE 'this is false' END |
+-------------------------------------------------------------+
| this is false                                               | 
+-------------------------------------------------------------+
Comment

PREVIOUS NEXT
Code Example
Sql :: select nextval from sequence sql 
Sql :: How to drop a foreign key constraint in mysql ? 
Sql :: how to extract year from date in sql 
Sql :: sql get last inserted row 
Sql :: insert current date sql 
Sql :: cursor.execute in python sqlite3 
Sql :: sql function 
Sql :: how to export only procedures mysql 
Sql :: mysql clear screen 
Sql :: drop multiple columns in sql 
Sql :: sql select into statement 
Sql :: create a sqlite database c# 
Sql :: database dump mysql command 
Sql :: java sql timestamp now 
Sql :: create mysql database on windows 
Sql :: sql drop column 
Sql :: mysql copy table to another table 
Sql :: how to identify locked tables in sql server 
Sql :: oracle list grants on package 
Sql :: how to put value in variable mysql 
Sql :: use group_concat in concat 
Sql :: mysql cast null to string 
Sql :: How to pass password to mysql command line 
Sql :: postgresql function 
Sql :: stored procedure to delete data from table in mysql 
Sql :: sql server add time to date 
Sql :: PostgreSQL types and C# types 
Sql :: mysql remove auto increment 
Sql :: SQL query to verify the size of the table 
Sql :: restart serial number for postgres 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =