darklinboxs
2018-05-24 14:56
采纳率: 51.9%
浏览 633

SQL 代替值问题,求大神解救

求大神解救,把性别中的1,变成女,2变成男,怎么实现,求对应SQL语句;
现SQL语句如下:
select a.cno as 员工编号,a.cname as 姓名, a.sexno as 性别,b.deptname as 部门,a.cdt as 入职日期,c.cbdt as 合同签订日期,c.cedt as 合同结束日期 from hr_epm_main as a
left join dept as b on a.dept=b.deptno
left join hr_epm_cont as c on c.secondside=a.cno
where a.empstatus='01'and a.cname not like '系统%'

现查询结果如下:
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • fsy351 2018-05-24 15:25
    已采纳
     select a.cno as 员工编号,a.cname as 姓名,_ CASE a.sexno WHEN 1 THEN '女' ELSE '男' END as 性别,_b.deptname as 部门,a.cdt as 入职日期,c.cbdt as 合同签订日期,c.cedt as 合同结束日期 from hr_epm_main as a
    left join dept as b on a.dept=b.deptno
    left join hr_epm_cont as c on c.secondside=a.cno
    where a.empstatus='01'and a.cname not like '系统%'
    
    点赞 评论
  • xx_rj 2018-05-24 14:58

    CASE a.sexno WHEN 1 THEN '女' ELSE '男' END

    点赞 评论
  • lq732830792 2018-05-25 01:20

    用的oracle数据库的话可以直接用decode函数的, decode(a.sexno,'1','女','2','男','') as 性别

    点赞 评论
  • darklinboxs 2018-05-25 02:07

    感谢@
    fsy351和@xx_rj ,因为@fsy351比较贴心一点,就选了你了,谢谢各位。

    点赞 评论
  • 芬芳酩酊 2018-05-25 08:38

    select a.cno as 员工编号,a.cname as 姓名,
    CASE
    when a.sexno=1 then '女'--1是女
    when a.sexno=7369 then '男'--2是男
    else '男'--默认是男
    end
    性别,--别名

    b.deptname as 部门,a.cdt as 入职日期,c.cbdt as 合同签订日期,c.cedt as 合同结束日期 from hr_epm_main as a
    left join dept as b on a.dept=b.deptno
    left join hr_epm_cont as c on c.secondside=a.cno
    where a.empstatus='01'and a.cname not like '系统%'

    点赞 评论
  • 芬芳酩酊 2018-05-25 08:40

    select a.cno as 员工编号,a.cname as 姓名,
    **
    CASE
    when a.sexno=1 then '女'
    when a.sexno=7369 then '男'
    else '男'
    end
    性别,
    **
    b.deptname as 部门,a.cdt as 入职日期,c.cbdt as 合同签订日期,c.cedt as 合同结束日期 from hr_epm_main as a
    left join dept as b on a.dept=b.deptno
    left join hr_epm_cont as c on c.secondside=a.cno
    where a.empstatus='01'and a.cname not like '系统%'

    点赞 评论

相关推荐 更多相似问题