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 9076849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:11:56+00:00 2026-06-16T19:11:56+00:00

I am a fairly experienced SQL Server developer but this problem has me REALLY

  • 0

I am a fairly experienced SQL Server developer but this problem has me REALLY stumped.

I have a FUNCTION. The function is referencing a table that is something like this…

PERFORMANCE_ID, JUDGE_ID, JUDGING_CRITERIA, SCORE  
--------------------------------------------------  
101, 1, 'JUMP_HEIGHT', 8   
101, 1, 'DEXTERITY', 7  
101, 1, 'SYNCHRONIZATION', 6  
101, 1, 'SPEED', 9  
101, 2, 'JUMP_HEIGHT', 6   
101, 2, 'DEXTERITY', 5  
101, 2, 'SYNCHRONIZATION', 8  
101, 2, 'SPEED', 9  
101, 3, 'JUMP_HEIGHT', 9   
101, 3, 'DEXTERITY', 6  
101, 3, 'SYNCHRONIZATION', 7  
101, 3, 'SPEED', 8  
101, 4, 'JUMP_HEIGHT', 7   
101, 4, 'DEXTERITY', 6  
101, 4, 'SYNCHRONIZATION', 5  
101, 4, 'SPEED', 8  

In this example there are 4 judges (with IDs 1, 2, 3, and 4) judging a performance (101) against 4 different criteria (JUMP_HEIGHT, DEXTERITY, SYNCHRONIZATION, SPEED).
(Please keep in mind that in my real data there are 10+ criteria and at least 6 judges.)

I want to aggregate the results in a score BY JUDGING_CRITERIA and then aggregate those into a final score by summing…something like this…

SELECT SUM (Avgs) FROM
(SELECT AVG(SCORE) Avgs 
  FROM PERFORMANCE_SCORES
  WHERE PERFORMANCE_ID=101
  GROUP BY JUDGING_CRITERIA) result 

BUT… that is not quite what I want IN THAT I want to EXCLUDE from the AVG the highest and lowest values for each JUDGING_CRITERIA grouping. That is the part that I can’t figure out. The AVG should be applied only to the MIDDLE values of the GROUPING FOR EACH JUDGING_CRITERIA. The HI value and the LO value for JUMP_HEIGHT should not be included in the average. The HI value and the LO value for DEXTERITY should not be included in the average. ETC.

I know this could be accomplished with a cursor to set the hi and lo for each criteria to NULL. But this is a FUNCTION and should be extremely fast.

I am wondering if there is a way to do this as a SET operation but still automatically exclude HI and LO from the aggregation?

Thanks for your help. I have a feeling it can probably be done with some advanced SQL syntax but I don’t know it.

One last thing. This example is actually a simplification of the problem I am trying to solve. I have other constraints not mentioned here for the sake of simplicity.

Seth

  • 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-06-16T19:11:57+00:00Added an answer on June 16, 2026 at 7:11 pm

    EDIT: -Moved the WHERE clause to inside the CTE.
    -Removed JudgeID from the partition

    This would be my approach

    ;WITH Agg1 AS 
    (
        SELECT   PERFORMANCE_ID
                ,JUDGE_ID
                ,JUDGING_CRITERIA
                ,SCORE
                ,MinFind    = ROW_NUMBER() OVER (   PARTITION BY     PERFORMANCE_ID
                                                                    ,JUDGING_CRITERIA
                                                    ORDER BY SCORE ASC  )
                ,MaxFind    = ROW_NUMBER() OVER (   PARTITION BY     PERFORMANCE_ID
                                                                    ,JUDGING_CRITERIA
                                                    ORDER BY SCORE DESC )
        FROM PERFORMANCE_SCORES
        WHERE PERFORMANCE_ID=101
    )
    SELECT AVG(Score)
    FROM Agg1
    WHERE MinFind > 1
    AND MaxFind > 1
    GROUP BY JUDGING_CRITERIA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly experienced with Oracle analytic functions but this one has stumped me. I'll
I know this question has been asked before, but despite being a fairly experienced
I have plenty of experience with this in PHP, but am fairly new to
I fairly new to mysql but have MS SQL experience. Is it possible to
I'm a fairly experienced web developer, but I've never needed to work with video
I am a fairly experienced (mid-level) developer that has spent quite a bit of
I am a fairly experienced OpenMP user, but I have just run into a
I'm don't have much experience in writing SQL so maybe this is a fairly
I'm very experienced with CSS but this one has me confused - apologies if
I'm a fairly experienced .NET desktop developer, but I'm new to Silverlight. I'm trying

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.