Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find the peak hour
Message
De
18/07/2014 13:45:44
 
 
À
18/07/2014 13:37:57
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01604117
Message ID:
01604118
Vues:
55
>Hi All -
>
>Here is a interesting problem for all you SQL experts. I am not sure it is possible but I thought I would ask anyway. I have a table containing 24 hour traffic counts. The counts are taken every 15 minutes and the data is stored in columns P1 thru P96. Thus the first hour of the day from midnight to 1:00 AM is stored in P1-P4 and the total for the hour would be (P1+P2+P3+P4). The challenge is to find the one hour block that contains the highest total for the day. The one hour block may begin at any of the 15 minute time periods (any P column up to P93). The desired result would provide the beginning of the time period (P column) and the total for the hour.
>
>The problem is easy enough to solve with VB after the data is loaded into a grid or table but the current challenge is to solve it with an SQL query so it could be stored into a parameterized view and used with a GIS interface. Any thoughts as to whether this is even possible?
>
>- D

Don, I have an answer that uses unpivot and recursion with common table expressions. It needs a little adapting, but if no one replies I'll post an answer later.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform