Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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 :: bigquery get last month 
Sql :: mysql create table query 
Sql :: rename column mysql 
Sql :: using minus query in SQL 
Sql :: sql server convert to guid 
Sql :: sql server delete table 
Sql :: sqlite3 update select 
Sql :: ON DUPLICATE KEY UPDATE for postgres 
Sql :: sql server select another database 
Sql :: plpgsql if statement 
Sql :: sql sequence 
Sql :: sql where part of string match 
Sql :: exec procedure oracle 
Sql :: multiple count with where clause sql 
Sql :: mysql with 
Sql :: mac django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? 
Sql :: sql select from multiple tables without join 
Sql :: get locked tables sql server 
Sql :: mysql if else 
Sql :: mysql changer nom table 
Sql :: sql server version check 
Sql :: how to get nth number in sql 
Sql :: mysql sql select one day before 
Sql :: oracle gather table statistics 
Sql :: mysql remove database 
Sql :: postgresql create table many-to-many 
Sql :: power bi union columns 
Sql :: joins in sql 
Sql :: delete from select postgresql 
Sql :: flask-sqlalchemy filter_by contains 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =