Skip to Main Content

Endeca Experience Management

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Find players who are above-average age of their teammates query

User_JUW53Nov 30 2020

Hi all! I am just beginning to learn the ins and out of database querying and have been stuck on this particular query for quite a while.
I am trying to list the names of players who are above average age of their teammates.
A few of my attempts have gotten close, but are not returning the right results.
Ideally I am trying to find the average age grouped by team, and test each player to see if they are older than that value.
My relational schema are as follows:
player(player_name, age, field_position)
plays_for(player_name, team_name)
This is my proposed query that runs without error, but returns me players above the total average age, not the average age of their respective team.
Any and all help or insight would be greatly appreciated.
A friend suggested perhaps making 2 copies of players and plays_for, but I'm unfamiliar with that technique.

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

select A.player_name 
  from plays_for A
  join player B 
    on A.player_name = B.player_name
 where B.age > (select avg(age) from player
group by A.team_name

Comments

Post Details

Added on Nov 30 2020
0 comments
339 views