指纹考勤记录怎么转换成考勤表呀!

ztwz 2013-11-22 11:07:15
指纹库中有两张表一张是用户表字段如下
code name
2001 张三
2002 李四
2003 王五
.....
一张是指纹打卡记录表字段如下
编号 打卡时间
2001 2013/7/15 7:42
2001 2013/7/15 18:00
2002 2013/7/16 7:45
2002 2013/7/16 18:03
2003 2013/7/17 7:32
2001 2013/7/22 7:49
2003 2013/7/22 18:07
.....

现在我想把两张表转换成考勤表如下

请问我要这sql要怎么写?sql弱到爆想了一下午硬没搞出来。

...全文
1575 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
这个就是行列转换问题。百度一下,帖子一大把。另外考勤这个东西,如果某天都没打卡,那么这个时间就不会出现在打卡记录表里面,所以写语句之前,考虑怎么把需要统计的时间范围之类的所有时间都给生成,防止缺少某天的日期
xxfvba 2013-11-26
  • 打赏
  • 举报
回复
我的想法添加一张临时表,然后动态行专列 create table #t(code int, name varchar(20)) insert into #t select 2001, '张三' union all select 2002 , '李四' union all select 2003 , '王五' create table #tb(code int,checktime datetime) insert into #tb select 2001 ,'2013/7/15 7:42' union all select 2001, '2013/7/15 18:00' union all select 2002, '2013/7/16 7:45' union all select 2002, '2013/7/16 18:03' union all select 2003, '2013/7/17 7:32' union all select 2001, '2013/7/22 7:49' union all select 2003, '2013/7/22 18:07' select name,case when CONVERT(varchar,checktime,108)>'12:00' THEN '下午' else '上午' end as [day], CONVERT(varchar,checktime,108)as tim,CONVERT(varchar,checktime,111)as dat into #test from #tb a,#t b where a.code=b.code declare @s varchar(max) select @s=ISNULL(@s+',','')+'['+dat+']' from #test group by dat order by dat set @s='select * from #test pivot (max(tim) for dat in ('+@s+'))A order by name,day' exec (@s)
q465897859 2013-11-23
  • 打赏
  • 举报
回复
人员表关联 指纹表 case when 判断下 就 ok了
ztwz 2013-11-23
  • 打赏
  • 举报
回复
这个表可以从新设计,在导入数据的时候添加到更合理的表中。
Q315054403 2013-11-23
  • 打赏
  • 举报
回复
设计问题,非SQL查询问题
---涛声依旧--- 2013-11-23
  • 打赏
  • 举报
回复
要用存储过程来实现了
LongRui888 2013-11-23
  • 打赏
  • 举报
回复
查询结果:
LongRui888 2013-11-23
  • 打赏
  • 举报
回复
这样吗:


--drop table t
--drop table tb
--go

create table t(code int, name varchar(20))

insert into t
select 2001,   '张三'
union all select 2002  , '李四'
union all select 2003  , '王五'
 
create table tb(编号 int,打卡时间 datetime)

insert into tb
select 2001   ,'2013/7/15 7:42'	
union all select 2001,   '2013/7/15 18:00'	
union all select 2002,   '2013/7/16 7:45'	
union all select 2002,   '2013/7/16 18:03'	
union all select 2003,   '2013/7/17 7:32'	
union all select 2001,   '2013/7/22 7:49'	
union all select 2003,   '2013/7/22 18:07'
go


select t.name,tt.v,
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='01'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '01',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='02'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '02',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='03'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '03',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='04'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '04',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='05'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '05',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='06'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '06',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='07'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '07',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='08'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '08',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='09'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '09',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='10'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '10',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='11'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '11',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='12'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '12',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='13'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '13',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='14'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '14',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='15'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '15',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='16'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '16',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='17'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '17',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='18'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '18',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='19'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '19',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='20'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '20',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='21'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '21',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='22'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '22',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='23'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '23',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='24'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '24',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='25'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '25',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='26'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '26',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='27'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '27',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='28'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '28',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='29'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '29',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='30'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '30',
       max(case when substring(CONVERT(varchar(10),打卡时间,120),9,2)='31'
                     then convert(varchar(5),打卡时间,114)
                else null
           end) as '31'
       
from t
inner join 
(
 select '上午' v,'00:00:00' as min_v,'12:00:00' as max_v
 union all select '下午','12:00:00', '00:00:00'
)tt
 on 1 = 1
left join tb
       on t.code = tb.编号
          and CONVERT(varchar(8),打卡时间,114) >= tt.min_v
          and CONVERT(varchar(8),打卡时间,114) < tt.max_v
group by t.code,t.name,tt.v
1、使用须知 1 1.1 用BIOCLOCK 激活软件 2 2、绪论 5 2.1 基本概念 7 2.1.1 用户的登记 7 2.1.2 用户的验证 7 2.1.3 匹配阀值 8 2.1.4 用户的ID号码 9 2.1.5 权限级别 9 2.1.6 初始界面 9 2.2 指纹的按压方式 10 3、登记和验证过程 11 3.1 登记用户 12 3.2 检测登记效果 17 3.3 备份登记 17 3.4 验证身份 17 3.4.1 指纹验证 18 3.4.2 密码验证 18 3.4.3 ID+指纹 19 3.5 登记成功的提示 20 4、设置 21 4.1 系统设置 21 4.1.1 时间设置 22 4.1.2 语言 22 4.1.3 锁驱动 22 4.1.4 高级设置 22 4.2 电源管理 23 4.3 通讯设置 24 4.4 记录设置 25 4.5 门禁功能设置 26 4.5.1、时间段 的功能定义 26 4.5.2、用户门禁设置 27 4.5.3、分组功能定义 28 4.5.4、开锁组合功能定义 28 4.5.5、锁驱动时长 29 4.6 自动检测 29 5 系统信息 29 6 维护 31 7. 软件的安装与卸载 31 8. 考勤管理程序 37 8.1 外接程序 37 8.1.1 下载考勤数据 37 8.1.2 员工及其指纹管理 38 8.1.3 考勤机管理 43 8.2. 维护/设置 44 8.2.1 维护/设置 44 8.2.2 部门表 45 8.2.3 员工维护 47 8.2.4 管理员设置 58 8.2.5 时间段维护 62 8.2.6 班次管理 65 8.2.7 员工排班 67 8.2.8 节日表 71 8.2.9 假类设置 72 8.2.10 考勤规则 73 8.2.11 数据库设置 76 8.3. 考勤处理 78 8.3.1 考勤处理 78 8.3.2 员工公出/请假设置 79 8.3.3 员工忘签到处理 88 8.3.4 员工忘签退处理 90 8.3.5 集体迟到处理 90 8.3.6 集体早退处理 91 8.4. 查询/打印 91 8.4.1 查询/打印 91 8.4.2 出勤记录 91 8.4.3 当前员工在岗情况 98 8.4.4 考勤异常查询与报表 100 8.5 数据 113 8.5.1 数据菜单 113 8.5.2 初始化系统 114 8.5.3 清除过期数据 114 8.5.4 备份数据库 116 8.5.5 导入考勤数据 116 8.5.6 导出考勤数据 118 8.5.7 重新登录系统 119 8.5.8 退出 119 9 附录 120 9.1 操作提示 120 9.1.1 确定起止日期 120 9.1.2 确定日期 120 9.1.3 选择员工 120 9.1.4 选择部门 121 9.1.5 选择部门员工 121 9.1.6 数据表处理工具条 122 9.1.7 导出数据 122 9.2 软件使用许可协议 126 10 常见问题解答 128 10.1 硬件设备 128 10.2 管理程序 129

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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