Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3628386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:00:37+00:00 2026-05-19T00:00:37+00:00

I’m facing a hard time to get the following query: Let’s say I have

  • 0

I’m facing a hard time to get the following query:

Let’s say I have a table with a lot of teams and each team has 15 players (one-to-many to a player table).

Those players are ordered within a team, through a Order column, from 0 to 14 and have two attributes:

  • Points scored (integer)
  • wasSick (boolean, or integer with values 0 for false or 1 for true)

I’d like a query that returns a row for each team, where the first column is the team ID (primary key) and the second column is the sum of the points scored from the first 11 players of each team that were not sick using the order defined by the Order column.

If more than 3 players were sick for a team, it would use all remaining ones.

This is against an Oracle database. I tried using ROWNUM but I need a similar rownum that resets for each aggregation. The query may contain subqueries or use the WITH clause.

Thanks!

PD: If you guessed, they are football/soccer teams.

EDIT

The attribute used to know the order of the players in a team is the order column. Let’s call it Position column, and it has integer from 0 to 14. So if in a team, players 2 and 4 are sick, I’d need the sum of the points made by players 0,1,3,5,6,7,8,9,10,11 and 12.

My attempt was something like:

SELECT t.id, sum(p.points) FROM team t, points p WHERE p.t_id = t.id AND p.wasSick = 0 AND ROWNUM < 12 GROUP BY p.t_id

What’s wrong here is that I’m missing ORDER BY p.position and that ROWNUM doesn’t reset between teams.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:00:38+00:00Added an answer on May 19, 2026 at 12:00 am

    Since there is no reference to a field that can be used to identify the first 11 players (if none of the players in the team are sick) I used rowid to order them. If you can update the question with such a field I can change the query. Till then :

    SELECT team_id,
           SUM(points)
      FROM (
            SELECT t.team_id, 
                   p.points
                   ROW_NUMBER() OVER(PARTITION BY team_id ORDER BY player_id, p.rowid) rn
              FROM teams t, players p
                  WHERE t.team_id = p.team_id
                    AND p.wasSick = 0
            )
     WHERE rn < 12
     GROUP BY team_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.