You're analyzing order data for a busy restaurant that tracks the number of orders received every minute throughout the day. Your task is to group these orders into 6-minute intervals and calculate the total orders for each interval.
Database Schema:
Table: Orders
+-------------+------+
| Column Name | Type |
+-------------+------+
| minute | int |
| order_count | int |
+-------------+------+The minute column is the primary key, representing the specific minute when orders were received. The order_count shows how many orders came in during that minute.
Interval Rules:
- Minutes 1-6 belong to Interval 1
- Minutes 7-12 belong to Interval 2
- Minutes 13-18 belong to Interval 3
- And so on...
Goal: Write a SQL query that calculates the total orders within each 6-minute interval and returns the results ordered by interval number ascending.
Input & Output
Visualization
Time & Space Complexity
Single pass through n records with O(log k) grouping operations where k is number of intervals
Storage for k interval groups in the result set
Constraints
- 1 ≤ minute ≤ 104
- 1 ≤ order_count ≤ 103
- The total number of rows is a multiple of 6
- minute is the primary key (no duplicate minutes)