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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:39:48+00:00 2026-06-05T11:39:48+00:00

I am looking for a way to perform basic outlier filtration on a column

  • 0

I am looking for a way to perform basic outlier filtration on a column of data in SQL server.

Background

I have a log table that contains various actions and the times at which those actions occurred. I am looking to retrieve some data surrounding the average time between two distinct log event types. I’m using a simple query (using DATEDIFF between timestamps) to capture the time duration between those events. Currently, I use an AVG function to get the average time for all paired instances of those two events occurring.

Problem

I would like to perform outlier filtration on the dataset prior to averaging using the following method:

Y is an outlier if Y < (Q1 - 1.5 * IQR) 
    OR
Y is an outlier if Y > (Q3 + 1.5 * IQR)

Where Q1 is the first quartile boundary value, 
      Q3 is the third quartile boundary value,
      and IQR is Q3 - Q1.

My question is first – what is the best way to determine quartile values in SQL and second – is there a way that I can store this as it’s own aggregate function to filter and then average?

  • 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-05T11:39:51+00:00Added an answer on June 5, 2026 at 11:39 am

    Let me presume that you are using SQL Server 2005 or later, since what you want to do requires window functions.

    select t.*
    from t cross join
         (select min(y) as q1, max(y) as q3, max(y) - min(y) as iqr
          from (select y,
                       row_number() over (order by y) as seqnum,
                       count(*) over (partition by null) as total
                from t
               ) t
          where seqnum = cast(total*0.25 as int) or seqnum = cast(total*0.75 as int)
         ) qs
     where (y < q1 - 1.5*iqr) or (y > q3 + 1.5*iqr)
    

    Some notes on how this works. The qs subquery is calculating the quartiles explicitly — by sequencing the rows (by y) and taking the value that is at the rows 25% and 75% of the way through the data. Note that the comparison compares the sequence number to the total of rows times that fraction cast back to an integer.

    The group by just puts these values into one row, for each of calculation. The where clause is the logic that you want to apply for exclusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been looking for a way to do complex queries like SQL can perform
My problem is that I was looking for way to use both storyboard and
Looking for a way to programatically, or otherwise, add a new instance of SQL
Coming from a non-OO background in Matlab, I'm looking to perform some of the
To clarify, I am looking for a way to perform a global search and
I'm looking for a way to perform pointer operations in C# or .NET in
I am looking for a way to perform a case insensitive string search within
I'm looking to store the contents of several dropdownlists in my SQL Server. Is
I'm looking for a way to manage consistent sets of changes across several data
I have a WinForms application and I am looking for a way to do

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.