暂无图片
假设有考勤表,请教如何通过sql查询只有签到没有签退的记录?
我来答
分享
暂无图片 匿名用户
假设有考勤表,请教如何通过sql查询只有签到没有签退的记录?
暂无图片 5M

假设有一个考勤记录,正常应该是有签到也有签退,并且发生在同一天。

表字段包括:

  1. type,值为“签到”和“签退”
  2. time,发生时间,比如2022-06-04 10:00:00
  3. username,账号等

现在想通过sql查询出某一天只有一项记录的(包括只有签到没有签退以及只有签退没有签到)的所有用户名,该如何操作?

感谢

我来答
添加附件
收藏
分享
问题补充
4条回答
默认
最新
Root__Liu

select username from a where a.type=0 and a.type<>1 and to_date(a.time ,‘yyyy-mm-dd’) =‘2022-06-04’;
union all
select username from a where a.type=1 and a.type<>0
and to_date(a.time ,‘yyyy-mm-dd’) =‘2022-06-04’
;

type值为0代表签到,为1代表签退。

暂无图片 评论
暂无图片 有用 0
赵勇

select username
from 考勤表
where time >=&begin_time
and time < &end_time
group by username
having count(distinct type)<2;

暂无图片 评论
暂无图片 有用 0
彭冲

补充描述一下问题:我觉得实际场景更多的是时间跨多天而不是只查某一天,通常是考勤员每周一去拉上周的数据,或者是其他的时间范围。

暂无图片 评论
暂无图片 有用 0
DarkAthena
select trunc(time) dt,username from 考勤表 where time >=&begin_time and time < &end_time group by username,trunc(time) having count(distinct type)<2;
暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏