I'm trying to write a SQL query to count the number of requests received every 15 minutes within the past hour. I want to return the last three 15 minute intervals.
My data looks like:
log_date, time
2022-11-18, 2022-11-18 17:00:00 UTC
2022-11-18, 2022-11-18 17:10:00 UTC
2022-11-18, 2022-11-18 17:20:00 UTC
2022-11-18, 2022-11-18 17:40:00 UTC
My query so far:
select log_date, FLOOR(unix_timestamp(time)) div (15 * 60) as intervals, count(*)
from data_log
where log_date >= date_sub(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'), 1)
and requests_recieved = true
group by log_date, time
order by intervals desc limit 3
I want it to look like:
log_date, time, count
2022-11-18, 2022-11-18 17:00:00 UTC, 2
2022-11-18, 2022-11-18 17:15:00 UTC, 1
2022-11-18, 2022-11-18 17:30:00 UTC, 1
Update: I'm using SparkSQL 2.3.1