首页 新闻 会员 周边 捐助

sql server 分组查询

0
悬赏园豆:20 [已解决问题] 解决于 2008-07-01 11:00
求救:<BR>&nbsp;我有个考勤表 snm_checkwork <BR>字段有 id,checktime(上班时间),leavetime(下班时间),status(状态),uid(FK_考勤人编号)<BR>我想查询出按考勤的人uid分组显示内容,即相同人的考勤纪录显示在一起 <BR>改怎么写 tsql语句啊?!
问题补充: 表中的所有字段都显示出来 只是显示的结果是将把相同uid的字段排列在一起
yeyang的主页 yeyang | 菜鸟二级 | 园豆:418
提问于:2008-06-30 12:07
< >
分享
最佳答案
0
select * from snm_checkwork order by uid select * from snm_checkwork order by uid desc
风海迷沙 | 老鸟四级 |园豆:4453 | 2008-06-30 12:57
其他回答(4)
0
没有明白你的需求,你的查询结果都有那些字段。
玉开 | 园豆:8822 (大侠五级) | 2008-06-30 12:16
0
是不是Group By K_考勤人编号 一下就可以了
沙加 | 园豆:3680 (老鸟四级) | 2008-06-30 12:50
0
具体也不清楚你要完成什么功能,象这种数据分析的处理最好能有存储过程来实现,我下面有个计算考勤加班计算的存储过程,你可以参考以下: CREATE proc aSP_OTCL_ADD as Begin declare @term datetime , @begindate datetime, @enddate datetime select @term=Term,@begindate=Begindate,@enddate=enddate from skyattendprocess select Badge,sum(Num) Num into #OTCL_BAL from ashift_details where term between @begindate and @enddate and TMWG='RTTM' group by badge --周六加班 select Badge,sum(Num) Num into #OT2_BAL from ashift_details where term between @begindate and @enddate and TMWG='OTTM' and TMWGSUB in ('OT2U') and datepart(weekday,term)=7 and Num<>0 group by badge --非周六加班 select Badge,sum(Num) Num into #OT_BAL from ashift_details where term between @begindate and @enddate and TMWG='OTTM' and not (TMWGSUB in ('OT2U') and datepart(weekday,term)=7 ) and Num<>0 group by badge insert aOTCL_BaL(Term,Badge) select @term,badge from #OTCL_BAL a where not exists(select 1 from aOTCL_BaL b where a.badge=b.badge and datediff(month,b.term,@term)=0 ) insert aOTCL_BaL(Term,Badge) select @term,badge from #OT2_BAL a where not exists(select 1 from aOTCL_BaL b where a.badge=b.badge and datediff(month,b.term,@term)=0 ) insert aOTCL_BaL(Term,Badge) select @term,badge from #OT_BAL a where not exists(select 1 from aOTCL_BaL b where a.badge=b.badge and datediff(month,b.term,@term)=0 ) update a set a.RThis =0 from aOTCL_Bal a where datediff(month,term,@term)=0 Update a set a.RThis=b.Num from aOTCL_Bal a, #OTCL_BaL b where a.badge=b.badge and datediff(month,a.term,@term)=0 --and datediff(month,b.term,@term)=0 Update a set a.Rtotal=a.Rlast+a.RThis ,a.RBal =a.Rlast+a.RThis-a.RUsed from aOTCL_Bal a where datediff(month,a.term,@term)=0 --加班(周六加班) Update a set a.O2This =0 from aOTCL_Bal a where datediff(month,term,@term)=0 Update a set a.O2This=b.Num from aOTCL_Bal a, #OT2_BaL b where a.bad
照清 | 园豆:205 (菜鸟二级) | 2008-06-30 15:10
0
呵呵,如果只是要显示到一起,直接加order by select * from snm_checkwork order by uid
丁学 | 园豆:18730 (专家六级) | 2008-06-30 19:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册