create table Employees (
  EmployeeID char(6) primary key not null,
 Name varchar(6) not null,
 Education varchar(4) not null,
 Birthday datetime not null,
 Sex bit not null default 1,
 WorkYear tinyint null,
 Address varchar(40),
 PhoneNumber char(12) null,
  Pepartment char(3) not null  
)
insert into Employees values('000001','王林','大专','1966-01-23',1,8,'中山路32-1-508','83355668',2);
insert into Employees values('010008','伍容华','本科','1976-03-28',1,3,'北京东路100-2','83321321',1);
insert into Employees values('020010','王向容','硕士','1982-12-09',1,2,'四牌楼10-0-108','83792361',1);
insert into Employees values('020018','李丽','大专','1960-07-30',0,6,'中山东路102-2','83413301',1);
insert into Employees values('102201','刘明','本科','1972-10-18',1,3,'虎距路100-2','83606608',5);
insert into Employees values('102208','朱骏','硕士','1965-09-28',1,2,'牌楼巷5-3-106','84708817',5);
insert into Employees values('108991','钟敏','硕士','1979-08-10',0,4,'中山路10-3-105','83346722',3);
insert into Employees values('111006','张石兵','本科','1974-10-01',1,1,'解放路34-1-203','84563418',5);
insert into Employees values('210678','林涛','大专','1977-04-02',1,2,'中山北路24-35','83467336',3);
insert into Employees values('302566','李玉珉','本科','1968-09-20',1,3,'热和路209-3','58765991',4);
insert into Employees values('308759','叶凡','本科','1978-11-18',1,2,'北京西路3-7-52','83308901',4);
insert into Employees values('504209','陈林琳','大专','1969-09-03',0,5,'汉中路120-4-12','84468158',4);
 select EmployeeID,Name,Address,Pepartment=
  case Pepartment
  when 1 then '财务部'
  when 2 then '人力资源部'
  when 3 then '经理办公室'
  when 4 then '研发部'
  when 5 then '市场部'
end  
from Employees
--(3) 使用if 语句实现以上功能 

解决方案 »

  1.   

    if 好像不行 你是不是想将 Employees 表的最后一列的编号换成对应的部门名称,如果是的话
    你可以这样写sql语句
    select EmployeeID,Name,Address,(select 部门名称 from 部门表 b where b.Pepartment =a.Pepartment )Pepartment from Employees a
      

  2.   

    oracle中没有if。。可用decode和case
      

  3.   

    mysql中我用(if (gg=1, 1,if (gg=0, 0,if (gg=2, 2,null))))as mm
    格式可以,我再带到实际中试试,应该没问题了,有问题再来,谢过
      

  4.   

    是oracle么?貌似那个case when then end语句写错了嘢。。
    如果写在存储过程中就可以。。
      

  5.   

    貌似存储过程中的if也不能嵌套在sql语句中使用吧。。只能用case when then end了。
      

  6.   

    mysql可以是因为那是个函数。又不是因为它是I和F两个字母。