永发信息网

求助sql里面如何将top5数据求和

答案:3  悬赏:0  手机版
解决时间 2021-03-10 04:51
  • 提问者网友:箛茗
  • 2021-03-09 20:41
select TOP 3 A.USED_TIME from attstatus a inner join perempms b
on a.staff_no=b.staff_no inner join paygroup c on b.pay_group=c.pay_group
where a.status_code='lat' and a.dates>=c.period_from and a.dates<=c.period_to
and a.used_time>0 and a.used_time<=120 and a.staff_no='D0001' order by a.dates
asc

我是这么写的top,然后如何进行sum呢?
最佳答案
  • 五星知识达人网友:孤独入客枕
  • 2021-03-09 21:18
select sum(USED_TIME) from (select TOP 3 A.USED_TIME from attstatus a inner join perempms b
on a.staff_no=b.staff_no inner join paygroup c on b.pay_group=c.pay_group
where a.status_code='lat' and a.dates>=c.period_from and a.dates<=c.period_to
and a.used_time>0 and a.used_time<=120 and a.staff_no='D0001' order by a.dates
asc)
全部回答
  • 1楼网友:执傲
  • 2021-03-09 23:05
table1 id name 1 100 2 200 3 300 4 300 5 400 select top 3 * from table1 结果: 1 100 2 200 3 300 select top 3 with ties * from table1 结果: 1 100 2 200 3 300 4 300
  • 2楼网友:逐風
  • 2021-03-09 22:17
select sum( A.USED_TIME) from attstatus a inner join perempms b on a.staff_no=b.staff_no inner join paygroup c on b.pay_group=c.pay_group where a.status_code='lat' and a.dates>=c.period_from and a.dates<=c.period_to and a.used_time>0 and a.used_time<=120 and a.staff_no='D0001' and rownum <4 order by a.dates desc
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯