Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.05 KB | None | 0 0
  1. -- 10.2.31-MariaDB-log
  2.  
  3. CREATE TABLE `example` (
  4.   `itemid` bigint(20) unsigned NOT NULL,
  5.   `clock` int(11) NOT NULL DEFAULT 0,
  6.   `value` bigint(20) unsigned NOT NULL DEFAULT 0,
  7.   KEY `key1` (`itemid`,`clock`)
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  9.  
  10. INSERT INTO example(itemid, clock, value) values
  11. (1,1200000001, 100),
  12. (1,1200000002, 300),
  13. (1,1200000301, 100),
  14. (1,1200000601, 300)
  15.  
  16. -- 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
  17.  
  18. -- For example, if i want timestamp between 1200000000 and 1200001200, i want to get result like this:
  19. 1200000000 - 100/200/300
  20. 1200000300 - 100/100/100
  21. 1200000600 - 300/300/300
  22. 1200000900 - 0/0/0
  23.  
  24. -- NOT LIKE THIS, where period between 1200000900 and 1200001200 just missed due to lack of data:
  25. 1200000000 - 100/200/300
  26. 1200000300 - 100/100/100
  27. 1200000600 - 300/300/300
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement