qSQL · Grouping & Aggregation · Practice Question
Count Rows per 15-Minute Bucket, per Symbol
Question
Given a table t with columns sym and time (a timestamp column), write a select query that returns the number of rows per 15-minute interval, per symbol.
For example:
t:([] sym:20?`A`B; time:2026.06.11D09:00:00+20?00:59:59)Solution
select numRows:count i by sym, timeBucket:00D00:15 xbar time from tAlternative Solution
select numRows:count i by sym, timeBucket:(60*15*1000000000) xbar time from tAlternative Solution
select numRows:count i by sym, timeBucket:15 xbar time.minute from tExplanation
xbar buckets a value down to the nearest multiple of a given size — x xbar y rounds y down to the nearest multiple of x. Used on a time column, this groups timestamps into fixed-width windows.
00D00:15 xbar timebuckets time into 15-minute windows, using a timespan literal (00D00:15 = 0 days, 0 hours, 15 minutes) to specify the bucket width directly and unambiguously.
The second alternative expresses the same 15-minute width in raw nanoseconds (60*15*1000000000: 15 minutes × 60 seconds × 1,000,000,000 nanoseconds), which works identically but is harder to read at a glance. The third converts each timestamp to its time of day in minutes first (time.minute) and buckets that into multiples of 15. This drops the date, so it only matches the other two when all rows are on the same day.
by sym, timeBucket:... then groups by both the symbol and the time bucket together, so count i counts rows within each symbol/window combination rather than across the whole table.