Jump to content

Recommended Posts

I have 2 tables:

 

Game

-game_id

-venue_id

-season_id

 

Points

-point_id

-game_id

-player_id

 

 

This query gets me what I want but it takes ~60 seconds.

SELECT sum( P.points )  from Points as P, Game as G where G.season_id='8' and P.game_id=G.game_id and G.venue_id in ( SELECT distinct G.venue_id from Points as P, Game as G where G.season_id='8' and P.player_id = '8963' and P.game_id=G.game_id )

 

 

What this accomplishes is gives me the total points at the venues where the player has played.

 

Anyone have any better options for this?

Link to comment
https://forums.phpfreaks.com/topic/226506-complex-query/
Share on other sites

Hi

 

Quick play, and not sure it can be done without a subselect of some kind. However using a  JOIN might be more efficient.

 

SELECT SUM(p.points)
FROM Points p
INNER JOIN Game g
ON p.game_id = g.game_id
INNER JOIN ( SELECT distinct G.venue_id 
from Points as p1 INNER JOIN Game as g1 ON and p1.game_id=g1.game_id 
where g1.season_id='8' 
and p1.player_id = '8963' ) s
ON g.venue_id = s.venue_id

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/226506-complex-query/#findComment-1169132
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.