sql - 排除空值

时间:2018-06-08 04:42:26

标签: mysql sql

如何删除这些非值列? 这是我的问题:

SELECT CASE 
            WHEN region = 'CENTRAL'
               THEN 'Central' 
             WHEN region = 'EASTERN'
               THEN 'Eastern'   
               WHEN region = 'NORTHERN'
               THEN 'Northern' 
             WHEN region = 'SOUTHERN'
               THEN 'Southtern'               
  END as Peninsular , 
             case 
             WHEN region = 'BINTULU'
               THEN 'BINTULU' 
             WHEN region = 'KUCHING'
               THEN 'Kuching'   
               WHEN region = 'SIBU'
               THEN 'Sibu' 
   END as Sarawak,
            case 
             WHEN region = 'KOTA KINABALU'
               THEN 'KOTA KINABALU' 
             WHEN region = 'LAHAD DATU'
               THEN 'LAHAD DATU'  
               WHEN region = 'SANDAKAN'
               THEN 'SANDAKAN'
               WHEN region = 'TAWAU'
               THEN 'TAWAU'
   END as Sabah,
   region  
FROM locinvaisle
group by region

Result of the query

4 个答案:

答案 0 :(得分:1)

如果region是您的关键值,请添加

...
FROM locinvaisle
WHERE region IS NOT NULL
...

答案 1 :(得分:0)

SELECT CASE 
            WHEN region = 'CENTRAL'
               THEN 'Central' 
             WHEN region = 'EASTERN'
               THEN 'Eastern'   
               WHEN region = 'NORTHERN'
               THEN 'Northern' 
             WHEN region = 'SOUTHERN'
               THEN 'Southtern'               
  END as Peninsular , 
             case 
             WHEN region = 'BINTULU'
               THEN 'BINTULU' 
             WHEN region = 'KUCHING'
               THEN 'Kuching'   
               WHEN region = 'SIBU'
               THEN 'Sibu' 
   END as Sarawak,
            case 
             WHEN region = 'KOTA KINABALU'
               THEN 'KOTA KINABALU' 
             WHEN region = 'LAHAD DATU'
               THEN 'LAHAD DATU'  
               WHEN region = 'SANDAKAN'
               THEN 'SANDAKAN'
               WHEN region = 'TAWAU'
               THEN 'TAWAU'
   END as Sabah,
   region  
FROM locinvaisle
WHERE region is not null AND region != ''
group by region

取决于区域是空还是空。

答案 2 :(得分:0)

尝试此查询。

添加此行

widget which you want to change the opacity

表名后面。

where region is not null AND region != ''

答案 3 :(得分:0)

添加条件 ...........

FROM locinvaisle where region!=''