Help w/ Easy Query

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

Help w/ Easy Query

Postby dirtyJ » Thu Apr 03, 2008 8:49 am

Trying to get started with learning SQL and want to test out a few things. Let's say I want to run a query to select the top n players based on # hands I have on them and then retrieve some stats about them. I tried the following:

[code2eo]
SELECT
p.player_name,
COUNT(hhps.id_player) AS N_HANDS,
SUM (hhps.amt_won) AS WINNINGS
FROM player p, holdem_hand_player_statistics hhps
GROUP BY p.player_name
ORDER BY COUNT(hhps.id_player) DESC
LIMIT 100;
[/code2eo]

So I want to get the top N (in this case 100) players based on # of hands I have on them, their name and total winnings. Obviously I can add to the stats I retrieve later, I'd just like to get the basics working right now.

Trouble is I get an out of disk space error when I try to run the query...only have about ~2gb free and can't really spare any space right now so is there something I can do to get this working? Am I even on the right track?

Also is there a way to do this through the Reports tab in PT3 itself? It seems like there ought to be but I don't know enough about this stuff yet. Thanks in advance!


-dirtyJ
dirtyJ
 
Posts: 2
Joined: Thu Apr 03, 2008 7:28 am

Re: Help w/ Easy Query

Postby APerfect10 » Thu Apr 03, 2008 1:21 pm

Try this:

[code43y]SELECT
p.player_name,
sq.ttl_hands,
sq.sum_amt_won
FROM
(SELECT
hhps.id_player,
COUNT(hhps.id_hand) as ttl_hands,
SUM(hhps.amt_won) as sum_amt_won
FROM
holdem_hand_player_statistics hhps
GROUP BY
hhps.id_player ) as sq,
player p

WHERE
sq.id_player = p.id_player

ORDER BY
sq.ttl_hands DESC

LIMIT 100[/code43y]

The above does the exact same thing your query does but is much more efficient/faster.

You will learn that SQL is like an art form. There are many ways to accomplish the same task. You need to find the best method for efficiency.

Best regards,

Derek
APerfect10
Site Admin
 
Posts: 4489
Joined: Sat Dec 08, 2007 6:03 pm


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

Who is online

Users browsing this forum: No registered users and 0 guests