+ -
当前位置:首页 → 问答吧 → 考勤系统

考勤系统

时间:2011-12-05

来源:互联网

在考勤系统中,access数据库有checkinout表和userinfo表,chenkinout表有userid和checktime字段,userinfo有userid和name字段,在access查询中:
“SELECT u.name, format(c.checktime,"YYYY-MM-DD") AS mydate, format(min(c.checktime),"hh:mm") AS intime, format(max(c.checktime),"hh:mm") AS outtime FROM checkinout AS c, userinfo AS u WHERE c.userid=u.userid GROUP BY format(c.checktime,"YYYY-MM-DD"), u.name;”
这样只能查询出在checkinout表有记录的数据,如果当天员工请假或者外出都没有打卡就会没有记录,我想把没有打卡的记录也显示出来,用“NULL”显示,查询语句该怎么写?

作者: lining0755   发布时间: 2011-12-05

access导入到SQL后,查询语句如下:
“declare @tyear as int,@tmonth as int
set @tyear=2011
set @tmonth=10
select distinct left(convert(varchar,c.checktime,120),10) as mydate,u.userid,u.name,(select substring(CONVERT(varchar, min(checktime), 120 ),12,5) from checkinout where left(CONVERT(varchar, checktime, 120 ),10)=left(convert(varchar,c.checktime,120),10) and userid=u.userid) as mintime,(select substring(CONVERT(varchar, max(checktime), 120 ),12,5) from checkinout where left(CONVERT(varchar, checktime, 120 ),10)=left(convert(varchar,c.checktime,120),10) and userid=u.userid) as maxtime
from checkinout as c,userinfo as u where year(c.checktime)=@tyear and month(c.checktime)=@tmonth order by u.userid,mydate”
该语句可以得到上面的效果,但是在access中实现不了,而且查询速度很慢要几分钟,请大家指正

作者: lining0755   发布时间: 2011-12-05

userinfo 去左连接 checkinout ,这样可以保留所有userinfo的数据
SQL code

SELECT u.name, format(c.checktime,"YYYY-MM-DD") AS mydate, format(min(c.checktime),"hh:mm") AS intime, format(max(c.checktime),"hh:mm") AS outtime FROM userinfo AS u LEFT JOIN checkinout AS c ON c.userid=u.userid GROUP BY format(c.checktime,"YYYY-MM-DD"), u.name

作者: hookee   发布时间: 2011-12-05

补充说明:我想要的效果就是能显示所有员工每天的出勤情况,没有记录的就以NULL显示

作者: lining0755   发布时间: 2011-12-05

引用 2 楼 hookee 的回复:
userinfo 去左连接 checkinout ,这样可以保留所有userinfo的数据
SQL code

SELECT u.name, format(c.checktime,"YYYY-MM-DD") AS mydate, format(min(c.checktime),"hh:mm") AS intime, format(max(c.checktime),"hh:mm") AS ou……


还是不能显示所有员工的信息,谢谢

作者: lining0755   发布时间: 2011-12-05

能不能改成每天都显示所有员工的姓名和日期,如果没有记录intime和outtime的记录就是null
如:checkinout userinfo
userid checktime userid name  
14 2011-12-02 8:30 14 张三
14 2011-12-02 17:50 13 李四
13 2011-12-02 8:25 12 王五
12 2011-12-02 8:10 11 周六
12 2011-12-02 17:57 10 游七
11 2011-12-02 18:00

查询结果如下
name mydate intime outtime
张三 2011-12-02 08:30 17:50
李四 2011-12-02 08:25 null
王五 2011-12-02 08:10 17:57
周六 2011-12-02 null 18:00
游七 2011-12-02 null null

作者: lining0755   发布时间: 2011-12-05

热门下载

更多