Help with subquery
Posted: Fri Jul 05, 2013 12:30 pm
I'm trying to create a custom stat which inludes a subquery.
My stat looks like:
SUM (CASE WHEN EXISTS
(SELECT 1 FROM
(SELECT (xxxxx) FROM tourney_hand_player_statistics thps_1 WHERE thps_1.id_player = 1 AND (xxxxx) ) as subtable WHERE subtable.xxxxxx AND subtable.id_hand = tourney_hand_player_statistics.id_hand)
THEN 1 ELSE 0 END)
(Sorry for deleting some part of my custom stats by xxxxxxx, frankly speaking I don't want to make my stat to be public.)
This stat is working perfectly until I want to get the result for the player who has id #1 in the database. But what should I do if I want to make this stat to work for any player (and put it to my HUD, for example?)
I tried to change ' WHERE thps_1.id_player = 1 ' to ' WHERE thps_1.id_player = tourney_hand_player_statistics.id_player ' , it seems to be giving a correct result, but running the quary takes a few HOURS.
What is the correct way to run a query including a subquery to ANY player?
Thanks a lot in advance!
My stat looks like:
SUM (CASE WHEN EXISTS
(SELECT 1 FROM
(SELECT (xxxxx) FROM tourney_hand_player_statistics thps_1 WHERE thps_1.id_player = 1 AND (xxxxx) ) as subtable WHERE subtable.xxxxxx AND subtable.id_hand = tourney_hand_player_statistics.id_hand)
THEN 1 ELSE 0 END)
(Sorry for deleting some part of my custom stats by xxxxxxx, frankly speaking I don't want to make my stat to be public.)
This stat is working perfectly until I want to get the result for the player who has id #1 in the database. But what should I do if I want to make this stat to work for any player (and put it to my HUD, for example?)
I tried to change ' WHERE thps_1.id_player = 1 ' to ' WHERE thps_1.id_player = tourney_hand_player_statistics.id_player ' , it seems to be giving a correct result, but running the quary takes a few HOURS.
What is the correct way to run a query including a subquery to ANY player?
Thanks a lot in advance!