Skip to content
Advertisement

SQL: How to select two employeeid within same team and have a team_score greater than 400 ? Mentioned the table schema below

Previous_teams

  • id (integer)
  • name (text)
  • team_score (real)

Team_members

  • team_id (integer)
  • employee_id (integer)
  • employee_name (text)
  • birthday (text)
  • popularity (real)

Q: How do I select a pair of employee ids that have worked in at least 5 prior teams where the (average)team_score was greater than 400 and count of teams where they worked together. Also avoid any duplicates. Example: team_id pairs of (1,2) need to be taken and not (2,1)

Advertisement

Answer

This is basically a self-join with some aggregation to count the teams that meet the conditions:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement