急求sql语句

smilyvm 2009-09-14 03:34:50
员工信息表
EmpCode(员工编码),EmpName(员工姓名),Sex(性别),Brithday(出生日期),DeptName(所在部门),Station(岗位)
要求根据员工信息表内容得到三个月之内退休的人员信息
男的退休年龄为60,根据Brithday计算,
女的退休年龄计算方式为如果岗位=‘领导’则55岁
如果岗位=‘工人’则退休年龄为50
...全文
120 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
木易随风 2009-09-14
  • 打赏
  • 举报
回复
select * from tb
where datediff(day,brithday,getdate())/365>=( case when sex='男' then 60 when sex='女' and station='领导' then 55 when sex='女' and station='工人' then 50 end)


已经测试。
rucypli 2009-09-14
  • 打赏
  • 举报
回复

select *
from tb
where (sex='男' and year(dateadd(d,30,Brithday))>=60)or
(sex='女' and Station='工人' and year(dateadd(d,30,Brithday))>=50)or
(sex='女' and Station='领导' and year(dateadd(d,30,Brithday))>=55)
fanzhouqi 2009-09-14
  • 打赏
  • 举报
回复
LZ 给点测试数据
昵称被占用了 2009-09-14
  • 打赏
  • 举报
回复
少个引号,颜色都不对了

select * from tb 
where sex='男' and Brithday<= dateadd(year,-60,dateadd(month,-3,getdate()))
or sex='女' and 岗位='领导' and Brithday<= dateadd(year,-55,dateadd(month,-3,getdate
()))
or sex='女' and 岗位='工人' and Brithday<= dateadd(year,-50,dateadd(month,-3,getdate
()))
smilyvm 2009-09-14
  • 打赏
  • 举报
回复
急,急,急,急,急,急
昵称被占用了 2009-09-14
  • 打赏
  • 举报
回复
select * from tb 
where sex='男' and Brithday<= dateadd(year,-60,dateadd(month,-3,getdate()))
or sex='女' and 岗位='领导 and Brithday<= dateadd(year,-55,dateadd(month,-3,getdate
()))
or sex='女' and 岗位='工人' and Brithday<= dateadd(year,-50,dateadd(month,-3,getdate
()))

xuejiecn 2009-09-14
  • 打赏
  • 举报
回复

select * from employee where abs(datediff(M,dateadd(y,birthday, case when sex='男' then 60
when 性别='女' and Station='领导' then 55 else 50 end),getdate()))<=3


也可以用union来完成这个查询了。

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧