Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. CREATE TABLE source
  2. AS
  3. SELECT *
  4. FROM ( VALUES
  5. ( 6, 1000 ),
  6. ( 6, 2000 ),
  7. ( 7, 5000 ),
  8. ( 7, 6000 )
  9. ) AS t(client_id, score);
  10.  
  11. client_id | score
  12. ----+---------+---
  13. 6 | 3000
  14. 7 | 11000
  15.  
  16. CREATE VIEW desired_view
  17. AS
  18. SELECT client_id, sum(score)
  19. FROM source
  20. GROUP BY client_id;
  21.  
  22. client_id | sum
  23. -----------+-------
  24. 6 | 3000
  25. 7 | 11000
  26. (2 rows)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement