Skip to content

Instantly share code, notes, and snippets.

@tphummel
Created July 24, 2012 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tphummel/3172277 to your computer and use it in GitHub Desktop.
Save tphummel/3172277 to your computer and use it in GitHub Desktop.
The New Tetris - "Lines Won" Queries
TNT Queries
-- select * from tntmatch t where not exists (select 'hi' from playermatch p where p.matchid = t.matchid);
-- select * from playermatch p where not exists (select 'hi' from tntmatch t where t.matchid = p.matchid);
-- select * from tntmatch t where (select count(matchid) from playermatch p where p.matchid = t.matchid) > 4;
--WRANK LINES WON (including own)
SELECT m.matchdate, p.username, pm.*,
(select count(playerid) from playermatch where matchid = pm.matchid) as pCt, (select ifnull(sum(`lines`),0) from playermatch where matchid = pm.matchid and wrank >= pm.wrank) as lines_won, (select group_concat(n.username) from playermatch b, player n where b.matchid = pm.matchid and n.playerid = b.playerid and b.playerid != pm.playerid) as opps
FROM playermatch pm, player p, tntmatch m WHERE pm.matchid = m.matchid AND p.playerid = pm.playerid AND (select count(playerid) from playermatch where matchid = pm.matchid) IN (4) ORDER BY lines_won DESC;
--ERANK LINES WON (including own)
SELECT m.matchdate, p.username, pm.*,
(select count(playerid) from playermatch where matchid = pm.matchid) as pCt, (select ifnull(sum(`lines`),0) from playermatch where matchid = pm.matchid and erank >= pm.erank) as lines_won FROM playermatch pm, player p, tntmatch m WHERE pm.matchid = m.matchid AND p.playerid = pm.playerid AND (select count(playerid) from playermatch where matchid = pm.matchid) IN (4) ORDER BY lines_won DESC;
--WRANK LINES WON (NOT including own)
SELECT m.matchdate, p.username, pm.*, (select count(playerid) from playermatch where matchid = pm.matchid) as pCt, (select ifnull(sum(`lines`),0) from playermatch where matchid = pm.matchid AND playerid != pm.playerid and wrank > pm.wrank) as won, (select group_concat(n.username) from playermatch b, player n where b.matchid = pm.matchid and n.playerid = b.playerid and b.playerid != pm.playerid) as opps FROM playermatch pm, player p, tntmatch m WHERE pm.matchid = m.matchid AND p.playerid = pm.playerid AND (select count(playerid) from playermatch where matchid = pm.matchid) IN (4) ORDER BY lines_won DESC;
--ERANK LINES WON (NOT including own)
SELECT m.matchdate, p.username, pm.*, (select count(playerid) from playermatch where matchid = pm.matchid) as pCt, (select ifnull(sum(`lines`),0) from playermatch where matchid = pm.matchid AND playerid != pm.playerid and erank > pm.erank) as lines_won FROM playermatch pm, player p, tntmatch m WHERE pm.matchid = m.matchid AND p.playerid = pm.playerid AND (select count(playerid) from playermatch where matchid = pm.matchid) IN (4) ORDER BY lines_won DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment