Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 10.2.31-MariaDB-log
- CREATE TABLE `example` (
- `itemid` bigint(20) unsigned NOT NULL,
- `clock` int(11) NOT NULL DEFAULT 0,
- `value` bigint(20) unsigned NOT NULL DEFAULT 0,
- KEY `key1` (`itemid`,`clock`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- INSERT INTO example(itemid, clock, value) values
- (1,1200000001, 100),
- (1,1200000002, 300),
- (1,1200000301, 100),
- (1,1200000601, 300)
- -- I want make 'select min,avg,max from example where timestamp between A and B group by timestamp/300, fill missing values with 0'. Query based on query from https://stackoverflow.com/questions/68283989/mysql-window-function-to-calculate-averages-or-maximums-every-5-minutes
- -- For example, if i want timestamp between 1200000000 and 1200001200, i want to get result like this:
- 1200000000 - 100/200/300
- 1200000300 - 100/100/100
- 1200000600 - 300/300/300
- 1200000900 - 0/0/0
- -- NOT LIKE THIS, where period between 1200000900 and 1200001200 just missed due to lack of data:
- 1200000000 - 100/200/300
- 1200000300 - 100/100/100
- 1200000600 - 300/300/300
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement