一共有三个表,部门表,职员表,工作天数表,想查询少于10天的就显示缺工
三张表联合查询一下,然后做个判断。应该是这意思吧。。。
select *,(case 工作天数 when 工作天数<10 then '缺工' else 工作天数 end) 工作情况
from
部门表 join 职员表
on ......
join 工作天数表
on .....
select
部门表.部门名称,
职员表.职员名称,
(case 工作天数 when 工作天数<10 then '缺工' else 工作天数 end) 工作情况
from
职员表
inner join 工作天数表 on 职员表.职员ID=工作天数表.职员ID
inner join 部门表 on 职员表.部门ID=部门表.部门ID
order by 部门表.部门ID;
参考自:mysql join语法 http://www.data.5helpyou.com/article209.html
select 【员工姓名】 from 【工作天数表】 where 【工作天数】<10; //查出出勤少于10天的员工姓名
select 【部门】 from 【职员表】 where 【员工姓名】=‘员工姓名’; //查出员工所在的部门
select a.【部门名称】 b.【员工姓名】c.【工作天数】from 【部门表】 a,【职员表】 b,【工作天数表】 c; where b.【员工姓名】=c.【员工姓名】 and 【出勤天数】<10;
select a.*,
b.*, /*这里是你想要的字段*/
(case 工作天数
when c.工作天数 < 10 then
'缺工'
else
c.工作天数
end) 工作情况
from 部门表 a, 职员表 b ,工作天数表 c
where a.职工id = b.职工id
and b.职工id = c.职工id
and a.部门名称=''--可以添加你的业务其他的条件