Optimization Problem - SQL

wrote a query in sql... it works for player that doesn't have a lot of data
if i check the Hero player it take over a min
how do i avoid such a long time?
is there a problem crossing between holdem_hand_player_statistics and holdem_hand_player_detail ?
if i check the Hero player it take over a min
- Code: Select all
SELECT (case when (count(PS.id_hand) != 0)
then (cast(sum(case when PD.id_action_p = (SELECT id_action from lookup_actions where action = 'F')
then 1 else 0 end) as real)
/ count(PS.id_hand))
else (-1)
end) as result,
count(PS.id_hand) as result2
FROM holdem_hand_player_statistics as PS , player as P , holdem_limit L
, holdem_hand_player_detail as PD WHERE PS.id_player = P.id_player AND PS.id_limit = L.id_limit
AND PS.position = 0 AND PD.id_player = P.id_player AND PS.id_hand = PD.id_hand
AND PS.flg_p_face_raise AND PD.amt_p_raise_facing = 0.16 AND P.player_name = '********' AND L.amt_bb = 0.04
how do i avoid such a long time?
is there a problem crossing between holdem_hand_player_statistics and holdem_hand_player_detail ?