我通过以下查询获得了以下数据
Select *
FROM
(Select RP.ins_user_id, RP.Loadno, Max(RP.trndte) 'M1', Min(RP.trndte)'M2', sum(RP.trnqty) 'QTY'
from
(select R.ins_user_id,R.trnqty, R.trndte,
"Loadno" =
case when
R.actcod = 'sstg' then R.lodnum
else R.to_lodnum
end
from dbo.RP_DlyTrn R
where R.oprcod IN ('LPCK', 'RLPCK')
and R.actcod in ('caspck', 'otrpck', 'palpck', 'pcepck','sstg', 'list-start')
and R.ship_id <> 0
and R.trndte between '08/18/2014 17:25:00' and '08/19/2014 8:00:00') RP
where RP.Loadno is not null
group by RP.ins_user_id, RP.Loadno) rp2
order by RP2.ins_user_id, RP2.Loadno
结果:
ins_user_id Loadno end time(M1) start time(M2) qty start_time suc load
AMCPHEE L00000971730 2014-08-19 07:59:30 2014-08-19 07:47:16 7 Null
CBOWLEG L00000968872 2014-08-18 18:35:37 2014-08-18 18:22:50 29 Null
CBOWLEG L00000968927 2014-08-18 18:43:03 2014-08-18 18:38:45 4 2014-08-18 18:45:55
CBOWLEG L00000968965 2014-08-18 18:52:20 2014-08-18 18:45:55 9 2014-08-18 18:54:50
CBOWLEG L00000969024 2014-08-18 18:58:24 2014-08-18 18:54:50 3 2014-08-18 19:00:48
CBOWLEG L00000969068 2014-08-18 19:16:23 2014-08-18 19:00:48 51 2014-08-18 19:00:48
CBOWLEG L00000969170 2014-08-18 19:22:45 2014-08-18 19:19:45 7 2014-08-18 19:24:34
CBOWLEG L00000969194 2014-08-18 20:07:41 2014-08-18 19:24:34 73
使用滞后函数我想得到每个用户每次加载后续加载的开始时间。