I am using postresql but i am realy bad at construting sql queries.
I have this query and it works:
SELECT handhistories FROM handhistories
JOIN pokerhands using (pokerhand_id)
JOIN gametypes using (gametype_id)
RIGHT OUTER JOIN playerhandscashkeycolumns using (pokerhand_id)
WHERE pokerhands.site_id=0
AND pokerhands.numberofplayers>=5 and pokerhands.numberofplayers<=7
AND (bigblind = 2 OR bigblind = 4 )
AND player_id in
(SELECT player_id FROM playerhandscashkeycolumns GROUP BY player_id
HAVING AVG(case didvpip when true then 100::real else 0 end) <= 20 )
but i also want to limit the last “having” from the bottom so it will be something like this, but ofcourse it does not work.
SELECT handhistories FROM handhistories
JOIN pokerhands using (pokerhand_id)
JOIN gametypes using (gametype_id)
RIGHT OUTER JOIN playerhandscashkeycolumns using (pokerhand_id)
WHERE pokerhands.site_id=0
AND pokerhands.numberofplayers>=5 and pokerhands.numberofplayers<=7
AND (bigblind = 2 OR bigblind = 4 )
AND player_id in
(SELECT player_id FROM playerhandscashkeycolumns GROUP BY player_id
HAVING AVG(case didvpip when true then 100::real else 0 end) <= 20
AND HAVING AVG(case didvpip when true then 100::real else 0 end) > 10 )
how to “save” value that is after the having so i can compare it also from the bottom?
Thank you all.
This is mostly what @wildplasser already pointed out
.. minus the mistake with
BETWEEN.. plus
JOINinstead ofINconstruct, which is usually faster in PostgreSQL... easier to read
You table-qualify some columns, like
pokerhands.site_id, but not others, likehandhistories, you might want to clean that up.