--- /dev/null
+== rende la view dei punteggi ==
+select m.ttok, m.tidx, g.code, g.tstamp, p.pts, u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' ORDER BY g.tstamp;
+
+
+== rende somma punteggi da una certa data ==
+select sum(p.pts), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' GROUP BY (u.login) ORDER BY sum(p.pts);
+
+== vicini al conteggio ==
+select (sum(p.pts) * 100 ) / count(p.pts), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-12-01 00:00:00' GROUP BY (u.login) ORDER BY (sum(p.pts) * 100 ) / count(p.pts);
+
+
+== conteggio esatto ==
+select (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' GROUP BY (u.login) ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts));
+
+== conteggio ancora più esatto ==
+select (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)), count(p.pts), u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' GROUP BY (u.login) ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) DESC, count(p.pts) DESC
--- /dev/null
+--
+-- briskin5 (bin5) related tables
+--
+
+DROP TABLE #PFX#bin5_matches;
+CREATE TABLE #PFX#bin5_matches (
+ code SERIAL PRIMARY KEY,
+ ttok text UNIQUE, -- token associated to the match
+ tidx integer -- table index
+ );
+
+DROP TABLE #PFX#bin5_games;
+CREATE TABLE #PFX#bin5_games (
+ code SERIAL PRIMARY KEY,
+ mcode integer REFERENCES #PFX#bin5_matches (code) ON DELETE cascade ON UPDATE cascade,
+ tstamp timestamp -- end game time
+ );
+
+DROP TABLE #PFX#bin5_points;
+CREATE TABLE #PFX#bin5_points (
+ gcode integer REFERENCES #PFX#bin5_games (code) ON DELETE cascade ON UPDATE cascade,
+ ucode integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade,
+ pts integer -- points
+ );
+
--- /dev/null
+--
+-- try to start with a single table for all placings
+--
+-- tri = 0 lo = 0
+-- mon = 2 hi = 1
+-- wee = 4
+--
+
+DROP TABLE #PFX#bin5_places_mtime;
+CREATE TABLE #PFX#bin5_places_mtime (
+ code int,
+ mtime timestamp
+);
+INSERT INTO #PFX#bin5_places_mtime (code, mtime) VALUES (0, now());
+
+DROP TABLE #PFX#bin5_places;
+CREATE TABLE #PFX#bin5_places (
+ type integer,
+ rank integer,
+ ucode integer REFERENCES #PFX#users (code) ON DELETE cascade ON UPDATE cascade,
+ login text,
+ pts integer,
+ games integer,
+ score float
+);