-- this results in a rough median; the only problem is that we don't avg if it's an even number.  not a big deal truthfully, since eventually you'll have > 5

DROP VIEW current_scores;
CREATE OR REPLACE VIEW current_scores AS

    SELECT * FROM (SELECT * , row_number() OVER (PARTITION BY alocidispid, blocidispid, scorer ORDER BY score DESC) AS pcnum FROM
      (SELECT * FROM
        (SELECT percent_rank() over (PARTITION BY alocidispid, blocidispid ORDER BY score ASC) AS pc, * FROM
          (SELECT * FROM
            (SELECT *, row_number() OVER (PARTITION BY alocidispid, blocidispid ORDER BY created_at DESC) AS rownum FROM scores) tmp
              WHERE rownum < 6) AS score_ranked)
         AS tmp2 WHERE pc <= .5 ORDER BY pc DESC) pcs )
    AS final WHERE pcnum < 2;
