select a.*
from 表 a,(select 姓名,min(时间) as 时间 from 表 group by 姓名) b
where a.姓名=b.姓名 and a.时间=b.时间
from 表 a,(select 姓名,min(时间) as 时间 from 表 group by 姓名) b
where a.姓名=b.姓名 and a.时间=b.时间
解决方案 »
- sql server 2005的二个疑问
- 实时采集系统,想先把数据放在临时表后再导入数据表中怎么办?
- 两个相同数据库传输数据的问题
- 如何求得缺少的那部分数据
- 这样的表怎样查询 能查询出这样的结果,还有这样设计表可以吗?不好最好该怎么样设计。
- 请教set fmtonly on是如何工作的
- 关于SQL2000个人版在win7运行的问题
- 在程序中执行不了 存储过程,可能是什么原因??我把用到的用户的所有权限都加上了!
- 如何根据参数是否为空来查询
- a DBA want to export the full database but the user still
- 如何运行sql 无人值守安装
- 触发器问题
不过问题又来了。
这里我举的例子是已知只有两个人。
但是如果表的内容是从外部导入的,不知道总共会有多少人呢?
from 表 a,(select 姓名,min(时间) as 时间 from 表 group by 姓名) b
where a.姓名=b.姓名 and a.时间=b.时间 and datename(hour,getdate())<=12
union
select a.*
from 表 a,(select 姓名,min(时间) as 时间 from 表 group by 姓名) b
where a.姓名=b.姓名 and a.时间=b.时间 and datename(hour,getdate())>12
from 表 a,(select 姓名,max(时间) as 时间 from 表 group by 姓名) b
where a.姓名=b.姓名 and a.时间=b.时间 and datename(hour,getdate())<=12
union
select a.*
from 表 a,(select 姓名,min(时间) as 时间 from 表 group by 姓名) b
where a.姓名=b.姓名 and a.时间=b.时间 and datename(hour,getdate())>12
(select 編號,姓名,班別 ,min(時間) as 時間 from tb where 班別='上班签到' group by 編號,姓名,班別
union all
select 編號,姓名,班別 ,min(時間) as 時間 from tb where 班別='下班签到' group by 編號,姓名,班別)a
order by 編號,時間