Guest User

Untitled

a guest
Jan 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. CREATE TABLE book_rating (id TINYINT, name CHAR(30), star_rating TINYINT);
  2.  
  3. INSERT INTO book_rating VALUES (1, 'Lord of the Ladybirds', 5);
  4. INSERT INTO book_rating VALUES (2, 'Lord of the Ladybirds', 3);
  5. INSERT INTO book_rating VALUES (3, 'Lady of the Flies', 1);
  6. INSERT INTO book_rating VALUES (4, 'Lady of the Flies', 2);
  7. INSERT INTO book_rating VALUES (5, 'Lady of the Flies', 5);
  8. INSERT INTO book_rating VALUES (6, 'Lady of the Flies', 5);
  9. INSERT INTO book_rating VALUES (7, 'Lady of the Flies', 5);
  10. INSERT INTO book_rating VALUES (8, 'Lady of the Flies', 5);
  11. INSERT INTO book_rating VALUES (9, 'Lady of the Flies', 5);
  12. INSERT INTO book_rating VALUES (10, 'Lady of the Flies', 5);
  13. INSERT INTO book_rating VALUES (11, 'Lady of the Flies', 5);
  14. INSERT INTO book_rating VALUES (12, 'Lady of the Flies', 5);
  15. INSERT INTO book_rating VALUES (13, 'Lady of the Flies', 5);
  16. INSERT INTO book_rating VALUES (14, 'Lady of the Flies', 5);
  17. INSERT INTO book_rating VALUES (15, 'Lady of the Flies', 5);
  18.  
  19. // This works as expected
  20. SELECT name, median(star_rating) OVER (PARTITION BY name) FROM book_rating;
  21.  
  22. // This doesn't work
  23. SELECT name, median(star_rating) OVER (ORDER by id ROWS 3 preceding) from book_rating
  24.  
  25. // This works as expected
  26. SELECT name, avg(star_rating) OVER (ORDER by id ROWS 3 preceding) from book_rating
Add Comment
Please, Sign In to add comment