5.21打卡
Posted wanbeibei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.21打卡相关的知识,希望对你有一定的参考价值。
一、问题描述:
一只兔子躲进了10 个环形分布的洞中的一个。狼在第一个洞中没有找到兔子,就隔一个洞,到第3个洞去找;也没有找到,就隔2个洞,到第6个洞去找;以后每次多一个洞去找兔子……这样下去,如果一直找不到兔子,请问兔子可能在哪个洞中?
二、设计思路:
首先定义一个数组a[11],其数组元素为a[1],a[2],a[3]……a[10],这10个数组元素分别表示10个洞,初值均置为1。接着使用“穷举法”来找兔子,通过循环结构进行穷举,设最大寻找次数为1000次。由于洞只有10个,因此第n次查找对应第n%10个洞,如果在第n%10个洞中没有找到兔子,则将数组元素a[n%10]置0。当循环结束后,再检查a数组各元素(各个洞)的值,若其值仍为1,则兔子可能藏身于该洞中。
三、程序流程图
四、代码实现
#include<stdio.h>
int main()
int n=0,i=0,x=0;
int a[11];
for(i=0;i<11;i++)
a[i]=1;
for(i=0;i<1000;i++)
n+=(i+1);
x=n%10;
a[x]=0;
for(i=0;i<10;i++)
if(a[i])
printf("可能在第%d个洞\\n",i);
SQL 统计每日上班打卡和下班打卡语句
有以上员工打卡记录表
其中
Card_No为考勤卡号
Atte_time 为打卡时间
DoorInout为上班或下班,1为上班,0位下班
想统计没人每天最早上下班打卡,和其他上下班打卡 各去4笔 如不足则为空
如以下样式的表
-----------------------------------------
考勤卡号 日期 上班打卡 上班打卡1 上班打卡2 上班打卡3 下班打卡 下班打卡1 下班打卡2 下班打卡310890895 2013-08-10 16:04 20:24 NULL NULL 19:43 2013-08-11 00:46 NULL NULL10890895 2013-08-11 16:04 19:45 20:18 NULL NULL NULL NULL NULL
如果下班在第二天3点以内的也统计入下班打卡中下班打卡早于最早上班打卡的数据忽略
CREATE TABLE AtteTime
(
Card_No VARCHAR(10) ,
Atte_Time DATETIME ,
DoorInOut BIT
)
select A1.card_no,
A1.atte_time as "上班时间",
A2.atte_time as "上班时间1",
A3.atte_time as "上班时间2",
A4.atte_time as "上班时间3",
B1.atte_time as "下班时间",
B2.atte_time as "下班时间1",
B3.atte_time as "下班时间2",
B4.atte_time as "下班时间3"
from (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 1) A1
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 2) A2
on A1.card_no = A2.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 3) A3
on A1.card_no = A3.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 4) A4
on A1.card_no = A4.card_no
full join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 1) B1
on A1.card_no = B1.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 2) B2
on A1.card_no = B2.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 3) B3
on A1.card_no = B3.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 4) B4
on A1.card_no = B4.card_no
投入验证数据如下:
执行结果如下:
参考技术A 这是在oracle数据库下做的,不知道你是什么数据库,给你提供一下思路select
card_no,
attr_date,
to_char(atte_time,'HH24:MI')tim,
doorinout,
rn
from (
select
card_no,
attr_date,
atte_time,
doorinout,
ROW_NUMBER() OVER(PARTITION BY card_no,attr_date,doorinout ORDER BY atte_time asc) rn
from(
select
card_no,
(
case
when doorinout=1
then to_date(to_char(atte_time,'yyyy-MM-dd'),'yyyy-MM-dd')
when (doorinout=0 and to_number(to_char(atte_time,'HH24'))<3)
then (to_date(to_char(atte_time,'yyyy-MM-dd'),'yyyy-MM-dd')-1)
else to_date(to_char(atte_time,'yyyy-MM-dd'),'yyyy-MM-dd')
end
)attr_date,
atte_time,
doorinout
from AtteTime
) tmp order by card_no,atte_time asc,doorinout desc
) where rn < 5 参考技术B 能不能来一份数据 这么凭空想 或者构造数据 太麻烦 一些代表性的数据 就行。还有问题要描述清楚 :1)各 取 4笔还是各 去 4 笔,少了为空,多了呢?取时间早的还是时间晚的。
2) 没人每天是什么意思
3) 不经过调试 谁也不能保证自己写出的语句是100%正确的,给点代表性的数据。追问
上班,下班各去4笔数据,少了留空,多了去出去最早前4笔
每人每天的数据意思就是按照考勤号和日期进行分组
数据:字数限制放不上来
给分代表性的数据 错别字还是少点好
追问数据字数太长了放不上来,百度HI上给你吧.
以上是关于5.21打卡的主要内容,如果未能解决你的问题,请参考以下文章