how to link different tables?

Forum for users that want to write their own custom queries against the PT database either via the Structured Query Language (SQL) or using the PT3 custom stats/reports interface.

Moderator: Moderators

how to link different tables?

Postby Toasta » Mon Jan 05, 2009 1:50 pm

how can i link different tables?

for example i have this

SELECT player.id_player as PID,
player.player_name as PN,
ROUND(SUM(case when (flg_vpip) then 1 else 0 end)::numeric * (100::numeric / count(player_name)::numeric),2) as VPIP,
ROUND(SUM(case when (cnt_p_raise > 0) then 1 else 0 end)::numeric * (100::numeric / count(player_name)::numeric),2) as PFR,
SUM(amt_won) as Won,
ROUND(SUM(case when (flg_showdown) then 1 else 0 end)::numeric * (100::numeric / SUM(case when (flg_f_saw) then 1 else 0 end)::numeric),2)as WTSD,
Round((SUM(case when (enum_f_cbet_action = 'F') then 1 else 0 end)::numeric / SUM(case when (flg_f_cbet_def_opp) then 1 else 0 end)::numeric)*100,2) as foldtoflopcbet,
ROUND((SUM(cnt_r_raise) + SUM(case when (flg_r_bet) THEN 1 ELSE 0 END) + SUM(cnt_t_raise) + SUM(case when (flg_t_bet) THEN 1 ELSE 0 END) + SUM(cnt_f_raise) + SUM(case when (flg_f_bet) THEN 1 ELSE 0 END) ) ::numeric / ( SUM(cnt_r_call) + SUM(cnt_t_call) + SUM(cnt_f_call)),2) as totalaf,
count (player_name) as Hands
from player, holdem_hand_player_statistics
WHERE player_name = 'abcdef...'
AND holdem_hand_player_statistics.id_player = 1337
AND date_played between '2009-01-01' AND '2009-12-01'
GROUP BY player.player_name, player.id_player

now i want to add some values from holdem_hand_summary (look down), if i do so the query gets fucked up. how can i link them (i do not see any key to link :( ), its been a while till i had to use sql.

ROUND(SUM(CASE WHEN (holdem_hand_summary.amt_rake>=0.25 AND holdem_hand_summary.amt_rake<=0.5) THEN 1 ELSE 0 END) +
SUM(CASE WHEN (holdem_hand_summary.amt_rake>=0.51 AND holdem_hand_summary.amt_rake<=1) THEN 2 ELSE 0 END) +
SUM(CASE WHEN (holdem_hand_summary.amt_rake>=1.01 AND holdem_hand_summary.amt_rake<=1.5) THEN 3 ELSE 0 END) +
SUM(CASE WHEN (holdem_hand_summary.amt_rake>=1.51 AND holdem_hand_summary.amt_rake<=2) THEN 4 ELSE 0 END) +
SUM(CASE WHEN (holdem_hand_summary.amt_rake>=2.01 AND holdem_hand_summary.amt_rake<=3) THEN 6 ELSE 0 END) +
SUM(CASE WHEN (holdem_hand_summary.amt_rake>=3.01 AND holdem_hand_summary.amt_rake<=5) THEN 8 ELSE 0 END),2)

thanks.

edit :

final output should look like

Code: Select all
pid(int)   pn(text)   vpip(numeric)   pfr(numeric)   won(numeric)   wtsd(numeric)   foldtoflopcbet(numeric)   totalaf(numeric)   hands(bigint)
value      value      value           value          value          value           value                     value              value


this is working, but as soon as i add the fpp value it ends up like this

Code: Select all
pid(int)   pn(text)   vpip(numeric)   pfr(numeric)   won(numeric)   wtsd(numeric)   foldtoflopcbet(numeric)   totalaf(numeric)   hands(bigint) fpp(numeric)
value      value      value           value          value          value           value                     value              value         value   
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
value      value      value           value          value          value           value                     value              value         value
...
...
Toasta
 
Posts: 85
Joined: Mon Dec 10, 2007 2:54 am

Return to Custom Stats, Reports, and SQL [Read Only]

Who is online

Users browsing this forum: No registered users and 0 guests