## max(sum(expr))

Discuss how to create custom stats, reports and HUD profiles and share your creations.

### max(sum(expr))

Hello,

I would like to use max function with sum(cash_hand_player_statistics.amt_won) then I have tried :
max(sum(cash_hand_player_statistics.amt_won)) but it is not a valid SQL as you can see in my attached  files.

How can I do it please ^^,

Best regards,
9ae6
Attachments
9ae6

Posts: 21
Joined: Mon Jul 23, 2012 6:28 am

### Re: max(sum(expr))

What exactly are you trying to do here? "Sum" creates a single value (the total across all hands) so there is no "max" of that.
If you want to find the highest amount won in a single hand then you can just use:

max( cash_hand_player_statistics.amt_won )
WhiteRider
Moderator

Posts: 53384
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

### Re: max(sum(expr))

I am trying to create a loss limit indicator that tells me when to quit the game.
Then I don't want the highest amount won in a single hand

but

really the highest amount won from "net result" ( then the max after the sum of all amount won)

Any ideas?

Best regards,
9ae6
9ae6

Posts: 21
Joined: Mon Jul 23, 2012 6:28 am

### Re: max(sum(expr))

So you want to know the most you were up in the session? I'm not sure how to do that I'm afraid. It may be possible, but it would need a pretty advanced expression I think, and it's beyond my PostgreSQL ability.
WhiteRider
Moderator

Posts: 53384
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

### Re: max(sum(expr))

So you want to know the most you were up in the session?

Exactly

For example :
With loss limit = 100\$
If I go up to +300\$ and after I go down to +200\$ then I leave the game because (300 - 200 = 100) I have lost 100\$ from highest point.
If I go up to +80\$ .....................................-20\$ ......................................................(+80 - (-20) = 100)....................
etc.
9ae6

Posts: 21
Joined: Mon Jul 23, 2012 6:28 am

### Re: max(sum(expr))

Thanks for clarifying. I do not know how to do that I'm afraid, but one of the PostgreSQL experts on the forum may be able to help you.
WhiteRider
Moderator

Posts: 53384
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

### Re: max(sum(expr))

but one of the PostgreSQL experts on the forum may be able to help you.

Thanks so how can I contact him?
9ae6

Posts: 21
Joined: Mon Jul 23, 2012 6:28 am

### Re: max(sum(expr))

A few users of this forum are very good at PostgreSQL and if one of them sees this they may be able to help, but I didn't mean anyone specific, sorry for the confusion.

That data isn't stored in the database directly so it would take an advanced query to calculate it, if it is even possible.
WhiteRider
Moderator

Posts: 53384
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

### Re: max(sum(expr))

Hello,

Finally I have found myself. It is not 100% perfect because

Code: Select all
`cash_hand_player_statistics.amt_before`

without "max" is not cacheable then I have found another solution that works 99%.
Indeed if I not leave the game when I reach the loss limit and after I win a lot of money then the color stay "red". It is better than nothing.

Here my method to do it :

1°/I create the column "amt_max_stack_bb" with the expression :
Code: Select all
`max(cash_hand_player_statistics.amt_before / cash_limit.amt_bb)`

2°/I create the stat "max_stack_bb" with the expression :
Code: Select all
`amt_max_stack_bb`

3°/I create the stat "net_result" with the expression :
Code: Select all
`amt_won`

4°I create the stat "net_result_bb" with the expression
Code: Select all
`amt_bb_won`

4°/ Now in the section color condition of the stat "net_result", I need to compare money with money then I put:

RED :
Code: Select all
`#net_result_bb# <= #max_stack_bb# - 200`
(200 because I buyin 100bb and I want a 100bb loss limit then -100 -100 = -200. If you want a 200bb loss limit then put -300 because -100 -200 = -300 etc)

YELLOW :
Code: Select all
`#net_result_bb# < 0`

GREEN
Code: Select all
`#net_result_bb#  > 0`

My main problem is that I can not do so much since
Code: Select all
`cash_hand_player_statistics.amt_before`
is not cacheable.

So if someone has an idea to do it cacheable or another method to have a loss limit please let us know that would be cool

Best regards,
9ae6
Attachments
losslimit
9ae6

Posts: 21
Joined: Mon Jul 23, 2012 6:28 am