Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH totals AS
  2.  (
  3.  SELECT score_description,COUNT(*) AS student_count, score,
  4.     ( SELECT COUNT(*) FROM subtest_registration )  AS total_students  -- WHERE subtest_id = 'e696b230-10e0-11df-80f4-1a7fbecf21f7'
  5.    FROM subtest_registration_result
  6.    INNER JOIN subtest_registration ON subtest_registration_id=id
  7.    WHERE score_type_id = 2
  8.    GROUP BY score_description, score
  9.  )
  10. SELECT score_description, student_count,
  11. total_students,
  12. ( student_count * 100.00 ) /  total_students as percentage
  13.  FROM totals;
  14.  
  15.  
  16.  score_description | student_count | total_students |     percentage      
  17. -------------------+---------------+----------------+---------------------
  18.  M                 |          7803 |          40321 | 19.3521986061853625
  19.  B                 |          7996 |          40321 | 19.8308573696088887
  20.  E                 |         14596 |          40321 | 36.1994990203615982
  21.  W                 |          9926 |          40321 | 24.6174450038441507
  22. (4 rows)
  23.  
  24.  
  25. real    0m0.078s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement