sql server - Turning a flat SQL table into a report, aggregating numbers and nesting calculations/comparisons in a view query -
sql server - Turning a flat SQL table into a report, aggregating numbers and nesting calculations/comparisons in a view query -
i have huge flat table containing info handheld device. utilize generate reports 'site', done homegrown paas. study works great (allows view individual site), of calculations done on .net layer. need expand include key info on sites, in summarized type of way (line line each 'site'). have element (repeating panel) can display of info cycling through table or view, , lead user individual study (that exists on paas), need create view (i think best wrong?) hold summarized info displayed, id (site name) when item in repeating panel selected can drop user on individual site study requires.
so here goes nothing...
the database beingness used create reports based on security guard tags checked. extract info such average patrol times, tags missed on routes, alarms pressed etc haldheld device.
i have next coloumns of importance in tables:
data import- table 'transaction' info appears. every info line device.
-site name -route id -patrol id -type -tag name -occurrence date
route profiles- profile of route, containing total set of 'tags' route id can checked against see tags not checked in each patrol, , how 'successful' patrol guard was. dont neccessarily need utilize table aggregated understanding of how many tags checked in patrol, 'totaltags' value used check against.
-routeid -site name -totaltags -perfectpatrol
i trying obtain next basic stats. challenge generate view has aggregated calculations row row. each row cover previous day's 6am 6am window (based on occurrence date coloumn).for each site trying work out next (which sit down in 1 row of view):
1. patrols required - calculated counting number of "patrol started" occurences in 'type' coloumn site in question (each row belong site, , summarize site)
2. tags in route - pulled straight route profile table (match route id)
3. average patrol time - calculated measuring difference in 'occurrence date'(datetime) each patrol (unique patrol id's) in when 'patrol started' , 'patrol finished' value appear in type coloumn. aggregated, eg patrol of 10, of 12, , of 14, result in ave patrol time of 12 (minutes).
4. successful patrols - aggregated value number of patrols occurred in time window (percentage wise) either match or greater 'perfectpatrol' coloumn in route profile (this figure in perfectpatrol 100%) divided number of patrols required (see 1). basically, counting number of tags obtained in unique patrol, greater or equal number of tags in route (totaltags), on total number of patrols required (see 1)
5. incomplete patrol - patrol contained tags (less perfectpatrol percentage), not none. worth noting here, tag can identified occurrence of 'tag completed' in 'type' coloumn.
6. failed patrol - when no tags checked in patrol (so if in unique patrolid there no 'tag completed' values in 'type' coloumn).
7. total alarms raised - number of times 'callme' 'panic' or 'mandown' occurs in 'type' coloumn.
8. phone call me alarms - number of times 'callme' occurs in 'type' coloumn.
9. panic alarms - number of times 'panic' occurs in 'type' coloumn.
10. man downwards alarms - number of times 'mandown' occurs in 'type' coloumn.
things note: 1. there can multiple routes per site. preferrential each route have own row in case, sharing same site name. 2. each study on 24 hours, 6am 6am, , previous day. overriding filter on info import table ensure this.
i have no thought how approach due sheer size , complexity of of these operations existing within 1 huge sql query. mentioned, utilize in house paas requires little coding, hence me reaching out advice/help.
how go tackling problem?
sql sql-server
Comments
Post a Comment