Open Side Menu Go to the Top
Register
Holdem manager sql queries Holdem manager sql queries

05-29-2008 , 07:12 AM
I'm looking to run a few sql queries in postgressql but it might take me a long while to figure out which table holds which data etc. To help kick start me was wondering if anyone knew how to run a query to list players vpips for example? Thanks for any info.
Holdem manager sql queries Quote
05-29-2008 , 06:38 PM
The stats are in table 'compiledplayerresults' (positional stats are in 'compiledplayerresultspositionaction'). To filter records by player and date, you have to join them with table 'compiledresults':


Code:
SELECT 
 SUM(totalhands) AS HANDS,
 100.0*SUM(vpiphands)/SUM(totalhands) AS VPIP,
 100.0*SUM(pfrhands)/SUM(totalhands) AS PFR,
 1.0*SUM(totalbets)/SUM(totalcalls) AS AGG
 FROM compiledplayerresults 
  WHERE compiledplayerresults_id IN (
   SELECT compiledplayerresults_id FROM compiledresults
    WHERE player_id = 1234
    AND playeddate >= '2008-05-01 00:00:00');

You can get your 'player_id' by:

Code:
SELECT player_id FROM players 
 WHERE playername = 'Your_Name'
 AND site_id = 0 //0 is Party, -1 is alias, just see table 'pokersites'
Holdem manager sql queries Quote
05-31-2008 , 12:06 PM
Thanks a lot for this. Should help to start me off
Holdem manager sql queries Quote
06-02-2008 , 06:24 AM
I edited the original query a bit to get all players vpips and pfrs who have played 10 hands or more and also to handle divide by zero problem for calculating Agg.

SELECT cp.player_id, SUM(totalhands) AS HANDS,
100.0*SUM(vpiphands)/SUM(totalhands) AS VPIP,
100.0*SUM(pfrhands)/SUM(totalhands) AS PFR,
case when sum(totalcalls) = 0 then null else 1.0*SUM(totalbets)/SUM(totalcalls) end AS Agg
FROM compiledplayerresults cpr , compiledresults cp
WHERE cpr.compiledplayerresults_id = cp.Compiledplayerresults_id and numberofplayers between 5 and 6 and
gametype_id in (select gametype_id from gametypes where istourney = true) group by cp.player_id having count(totalhands) > 9 order by vpip desc ;

Does anyone know how to create an sql query to calculate players steal percentage.
Holdem manager sql queries Quote
06-19-2009 , 06:58 AM
Quote:
Originally Posted by peyote
Code:
SELECT 
 SUM(totalhands) AS HANDS,
 100.0*SUM(vpiphands)/SUM(totalhands) AS VPIP,
 100.0*SUM(pfrhands)/SUM(totalhands) AS PFR,
 1.0*SUM(totalbets)/SUM(totalcalls) AS AGG
 FROM compiledplayerresults 
  WHERE compiledplayerresults_id IN (
   SELECT compiledplayerresults_id FROM compiledresults
    WHERE player_id = 1234
    AND playeddate >= '2008-05-01 00:00:00');
Hello i can read out my player id with your sql query, but when i put in my player id (or any id else) into the query above im always getting an empty table?
Holdem manager sql queries Quote
06-19-2009 , 08:11 AM
1) Turn on logging on sql queries my changing postgres.conf
2) Get HEM to run a query similar to what you want
3) View log to see what query it executed
4) Tinker
Holdem manager sql queries Quote
06-19-2009 , 12:47 PM
Quote:
Originally Posted by brunowillis
Hello i can read out my player id with your sql query, but when i put in my player id (or any id else) into the query above im always getting an empty table?
There were some data model changes. This should work (for a while ):

Code:
SELECT 
 SUM(totalhands) AS HANDS,
 100.0*SUM(vpiphands)/SUM(totalhands) AS VPIP,
 100.0*SUM(pfrhands)/SUM(totalhands) AS PFR,
 1.0*SUM(totalbets)/SUM(totalcalls) AS AGG
 FROM compiledplayerresults_month
  WHERE compiledplayerresults_id IN (
   SELECT compiledplayerresults_id FROM compiledresults_month
    WHERE player_id = 1234
    AND playedonmonth >= '200906');
Holdem manager sql queries Quote
06-22-2009 , 06:52 AM
hey, is anyone able to write a query calculating the unweighted standard deviation of all the players in my database based on vpip over their sessions?

Will pay $$$ if anyone can help me do so.

cheers
Holdem manager sql queries Quote
07-20-2009 , 08:53 AM
Quote:
1) Turn on logging on sql queries my changing postgres.conf
2) Get HEM to run a query similar to what you want
3) View log to see what query it executed
4) Tinker
I tried that and the idea is nice but a query for vpip pfr and 3bet % looks like this:

Quote:
2009-07-20 14:47:52 CEST LOG: statement: unlisten *
2009-07-20 14:48:01 CEST LOG: statement: unlisten *
2009-07-20 14:48:01 CEST LOG: statement: select * from gametypes
2009-07-20 14:48:01 CEST LOG: statement: unlisten *
2009-07-20 14:48:01 CEST LOG: statement: select gt.gametypedescription as "gametypedescription",(case when gt.pokergame in (1) then 'holdem' when gt.pokergame in (2) then 'omaha' when gt.pokergame in (3) then 'omaha o8' end) as "gt.pokergame",gt.bigblind as "bigblind",count(ph.*) as totalhands,sum(case when didvpip = true then 1 else 0 end) as vpiphands, sum(case when ph.preflopaction_id <> -1 then 1 else 0 end) as totalplayablehands,sum(case when didpfr = true then 1 else 0 end) as pfrhands,sum(case when ph.preflopaction_id = 3 then 1 else 0 end) as couldcoldcall,sum(case when ph.firstpreflopactiontype_id = 2 and (ph.preflopaction_id = 3) then 1 else 0 end) as didcoldcall from playerhandscashkeycolumns ph join players pl on (pl.player_id = ph.player_id) join gametypes gt on gt.gametype_id = ph.gametype_id where (ph.player_id = 258) and (ph.gametype_id = 1 or ph.gametype_id = 2 or ph.gametype_id = 3 or ph.gametype_id = 4 or ph.gametype_id = 5 or ph.gametype_id = 13 or ph.gametype_id = 14 or ph.gametype_id = 15 or ph.gametype_id = 16 or ph.gametype_id = 20 or ph.gametype_id = 21 or ph.gametype_id = 22 or ph.gametype_id = 23 or ph.gametype_id = 24 or ph.gametype_id = 25 or ph.gametype_id = 26 or ph.gametype_id = 27 or ph.gametype_id = 28) and gt.pokergame = 1 group by "gametypedescription",(case when gt.pokergame in (1) then 'holdem' when gt.pokergame in (2) then 'omaha' when gt.pokergame in (3) then 'omaha o8' end) ,"bigblind" order by bigblind desc
2009-07-20 14:48:01 CEST LOG: statement: unlisten *
2009-07-20 14:48:01 CEST LOG: statement: unlisten *
2009-07-20 14:48:01 CEST LOG: statement: select PH.PokerHand_ID,PH.PreFlopPlayerActionType_ID,PH.S treetWentAllin,PH.HandTimeStamp,GT.GameTypeDescrip tion, GT.PokerGame,PH.holecard1int,PH.holecard2int,PH.ho lecard3int,PH.holecard4int,PKH.FlopCard1int,PKH.fl opcard2int,PKH.flopcard3int,PKH.TurnCardint,PKH.Ri verCardint,PH.flopplayerActionType_ID,PH.turnplaye rActionType_ID,PH.riverplayerActionType_ID,PH.NetA mountWon,GT.BigBlind,PH.PositionType_ID,PH.preflop action_id,PH.didpfr,PH.didvpip,(case when PH.StreetWentAllIn > 0 then (Select SklanskyBucks from AllInSituations where ph.playerhand_id = allinsituations.playerhand_id) else 0 end) as SklanskyBucks,(case when PH.StreetWentAllIn > 0 then (Select EquityPct from AllInSituations where ph.playerhand_id = allinsituations.playerhand_id) else 0 end) as EquityPct,getwinningplayerjoincashver2(ph.pokerhan d_id) as winningplayerjoin from playerhandscashkeycolumns ph join pokerhands pkh on ph.pokerhand_id = pkh.pokerhand_id join players pl on (pl.player_id = ph.player_id) join gametypes gt on gt.gametype_id = ph.gametype_id where (ph.player_id = 258) and (ph.gametype_id = 1 or ph.gametype_id = 2 or ph.gametype_id = 3 or ph.gametype_id = 4 or ph.gametype_id = 5 or ph.gametype_id = 13 or ph.gametype_id = 14 or ph.gametype_id = 15 or ph.gametype_id = 16 or ph.gametype_id = 20 or ph.gametype_id = 21 or ph.gametype_id = 22 or ph.gametype_id = 23 or ph.gametype_id = 24 or ph.gametype_id = 25 or ph.gametype_id = 26 or ph.gametype_id = 27 or ph.gametype_id = 28) and gt.pokergame = 1 and GT.GameTypeDescription = '$0.02/0.04 NL' and GT.PokerGame In (1) and mark_id = 1 order by PH.HandTimeStamp desc limit 100
2009-07-20 14:48:01 CEST LOG: statement: unlisten *

O_O It looks like im doing it wrong... Isnt there some list with all the important tables and stats locations?...
Holdem manager sql queries Quote
07-20-2009 , 01:09 PM
Yup looks good. It's not as complex as it looks. First query is for the top bit - the report. the second is the second section, the top 100 hands that fit the report. You can cut a fair amount out of the first query (half of it is just selecting the right game type/limit with "ph.gametype_id = 1 or ph.gametype_id = 2 or ph.gametype_id = ...")

The bit you are interested in is around here:

sum(case when didvpip = true then 1 else 0 end) as vpiphands,
sum(case when ph.preflopaction_id <> -1 then 1 else 0 end) as totalplayablehands
Holdem manager sql queries Quote
07-20-2009 , 03:55 PM
OK, you SQL qurus, anyone know how to put a statement in Excel and have the result populate a cell?

---------------Kitty
Holdem manager sql queries Quote
07-20-2009 , 03:59 PM
good luck with that

google searches might get you started, this was my first result
http://pcquest.ciol.com/content/handson/103040303.asp
Holdem manager sql queries Quote
10-18-2009 , 04:46 PM
Hi,

I need a detailed query done, basically i want to track the sum of profit/loss AFTER

1) I lost x buyins in a session (where i can just replace x with whatever number of buyins i want to use) So this would show me my profit/loss AFTER i lost 3 buyins in a session. When i say a session i mean a session where there wasnt more than 1 hour break in between the hands.
2) Same as above but instead of buyins i want to see how i done after i played say 2k hands in a sesson, again for all of these i want to know my profit/loss AFTER i reach 2k hands not including the 1st 2k hands
3) Same as above but where i played for longer than 2 hours again id like to see my profit/loss where ive played a session longer than 2 hours

If anyone can do this or even something close or maybe just one of them, can you please PM as i will offer a reward for your time, so pm me
Holdem manager sql queries Quote
12-02-2009 , 04:25 AM
Hi

There is stat in hem name:"fold to flop CB (oop)" and "fold to flop CB (ip)"

What kind of SQL-query I should make to count those stats?

I have read http://www.holdemmanager.net/forum/s...ead.php?t=3595 but found nothing.
Holdem manager sql queries Quote
02-18-2010 , 03:34 PM
Hey Guys, I just did some simple queries on hands, and I wanted to give props to MonkeyLunch, since looking at some of his posts saved me a lot of time (I like saving time).

I wrote a blog about it, with my queries in the end. It's for beginners really, so I lay out some of the basic things you need to know about the HEM database. If it helps even one person here, then this post is worth it.

http://www.pokerlistings.com/blog/po...ng-the-numbers

I'm not an SQL expert at all, so I was glad to find this thread with some tips. Thanks.
Holdem manager sql queries Quote
02-18-2010 , 04:17 PM
Quote:
Originally Posted by atari2600
Hey Guys, I just did some simple queries on hands, and I wanted to give props to MonkeyLunch, since looking at some of his posts saved me a lot of time (I like saving time).

I wrote a blog about it, with my queries in the end. It's for beginners really, so I lay out some of the basic things you need to know about the HEM database. If it helps even one person here, then this post is worth it.

http://www.pokerlistings.com/blog/po...ng-the-numbers

I'm not an SQL expert at all, so I was glad to find this thread with some tips. Thanks.
Hey great to hear the queries were useful to you! Nice blog post!
Holdem manager sql queries Quote
06-04-2010 , 01:21 PM
I want to use fold to resteal stat in my custom query.
Is anyone knows how to select this stat from the database?
Because I can't. I looked in every table, even tried to read postgres logs, but got nothing.
This community is my last hope!
Holdem manager sql queries Quote
06-06-2010 , 10:49 AM
How could i extract showdown winnings and or non-showdown winnings?
Looks like hm queries the db itself for these data?
tyvm
Holdem manager sql queries Quote
12-09-2010 , 10:33 AM
Quote:
Originally Posted by Hood
1) Turn on logging on sql queries my changing postgres.conf
2) Get HEM to run a query similar to what you want
3) View log to see what query it executed
4) Tinker
I know this is an old post and I'm embarassed I didn't think of this myself, but thanks.
Holdem manager sql queries Quote
05-18-2011 , 02:16 AM
been doing a bunch of queries thanks to this thread.

I found a table that keeps table_ids and table names. I wanted to see if I could find what tables the players in my recent hand histories were at.

Easy enough to filter for recent hand with lastplayeddate, but there weren't any more columns in the table that had tableids, so I couldn't figure out how to join that table with any of the others. anybody got any ideas?
Holdem manager sql queries Quote
05-18-2011 , 05:30 AM
not sure if this will help, a related function from my python lib of hem queries, seems you kinda want the reverse of what this does but the joins should help:

Code:
def get_playernames_from_tablename(tablename, last_x_hands=5):
    """
    Get list of playernames from players dealt in to the last x hands at the table.

    Todo: Currently hard-coded to cash-only. Need to do the same but for 'tourneykeycolumns'
    """
    c = connection.cursor()
    q = """select distinct p.playername from playerhandscashkeycolumns kc join (
        select * from pokerhands ph
        inner join tables t on ph.table_id = t.table_id
        where t.tablename = %(tablename)s
        order by handtimestamp desc
        limit %(last_x_hands)s) as ph
        on kc.pokerhand_id = ph.pokerhand_id
        join players p on p.player_id = kc.player_id
        order by p.playername asc"""

    c.execute(q, locals())
    return [c[0] for c in c.fetchall()]
Holdem manager sql queries Quote
05-20-2011 , 01:33 PM
ha wow, I actually forgot I made this post and figure out how to do it myself. Your way is much better though. thanks much!
Holdem manager sql queries Quote
05-21-2011 , 03:24 AM
so I've made a rough version of a new active player list for holdemmanager.

The problem I'm having now is updating the player list when the database gets new hands. Currently I just have to end the program and start it again.

I've tried using resultset.refreshrow() and it complains to me that none of the tables have primary keys set. When I try and use Alter Table it tells me I can't set multiple primary keys.

Any idea how I can get database updates without restarting the program?

I managed to get it to update the information occasionally by closing all the connections and reopening and then reloading the gui data. But for some reason that only works occasionally, which seems very strange to me.

I'll keep plugging away, but if anybody has any suggestions on how to update resultsets for database changes I could really use some pointers.
Holdem manager sql queries Quote
05-21-2011 , 06:43 PM
woo got that working too.
Holdem manager sql queries Quote

      
m