sql server - Need help with SQL query -
i have following data:
transactiontype lane transactiondate ------------------------------------------------ sale 17 2011-07-21 06:15:34 signon 18 2011-07-21 07:00:00 sale 18 2011-07-21 07:06:43 signon 20 2011-07-21 08:01:12 sale 18 2011-07-21 07:30:00 sale 18 2011-07-21 08:30:00 sale 18 2011-07-21 09:30:50 sale 20 2011-07-21 10:15:34 signoff 18 2011-07-21 19:00:00 signoff 20 2011-07-21 19:10:52
i need following information:
- the count of
lane
lie between signon , signoff transaction types - the total time each
lane
@ signon state, e.g. rowlane
number 18 12 hours, rowlane
20 has time of 11 hours, 9 minutes , 40 seconds
this of it... including multiple sign in/out per lane , how many transactions within each login/out time period. once result, can query total counts of active lanes / sessions whatever roll-up values... such total times lane 18 signed in/out total sales transactions, or overall how many lanes open , accounted such sale activity.
since group on lane, signon/off, applied min() hours, minutes, seconds constant per each signon/off session.
select prequery.lane, prequery.signedon, prequery.signedoff, min( datediff(hour, prequery.signedon, prequery.signedoff )) hours, min( datediff(minute, prequery.signedon, prequery.signedoff )) minutes, min( datediff(second, prequery.signedon, prequery.signedoff )) seconds, count(*) numofsales ( select t1.lane, t1.transactiondate signedon, min( t2.transactiondate ) signedoff trans1 t1 left join trans1 t2 on t1.lane = t2.lane , t2.transactiontype = "signoff" , t2.transactiondate > t1.transactiondate t1.transactiontype = "signon" group t1.lane, t1.transactiondate ) prequery left join trans1 t3 on prequery.lane = t3.lane , t3.transactiontype = "sale" , t3.transactiondate between prequery.signedon , prequery.signedoff group prequery.lane, prequery.signedon, prequery.signedoff
Comments
Post a Comment