有PRODUCT表, 有
Id, name , coutry, state 字段
我要查找PRODUCT表, 如果country字段的值为‘cn’,’tw’
就查出state字段, 如果是其他的值就查出country字段,
为空就不输出, 怎么写这条sql语句

解决方案 »

  1.   

    SQL> create table product (id number,name varchar2(16),country varchar2(32),stat
    e varchar2(2));表已创建。SQL> select case
      2            when country='cn' then state
      3            when country='tw' then state
      4            when country is null then null
      5            else country
      6          end result
      7  from product;未选定行SQL>
      

  2.   

    不想让null 出现在查询中, 这样写有很多null值
      

  3.   

    那么在where里过滤,where country is not null