2017-03-09 67 views
0

比方说,我有一个表Employeesempl_nr, start_date, empl_name, sex, empl_unit 其中unit1,2,3SQL:根据值,我可以在表格行旁边显示注释吗?

我要显示一个附加列这是不是在表中根据表中的数值意见。

I.E if unit='1'这意味着他们在巴黎工作,我想展示它;如果员工在2016年开始工作,那么他是新来者,我想在下面显示该信息示例

回答

2

您需要CASE。例如:

/* build a test case */ 
with test(n, y) as (
    select 1, 2016 from dual union all 
    select 2, 2000 from dual 
) 
/* the query */ 
select n, 
     case 
     when n = 1 then 'comment when n=1' 
     when n = 2 then 'comment when n=2' 
     end 
     || ' and ' || 
     case 
     when y > 2010 then 'year greater than 2010' 
     else 'year <= 2010' 
     end as comm 
from test; 

给出:

  N COMM 
---------- ------------------------------------------- 
     1 comment when n=1 and year greater than 2010 
     2 comment when n=2 and year <= 2010 
相关问题