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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:47:39+00:00 2026-06-08T20:47:39+00:00

I want to count how many times each user has rows within ‘5’ of

  • 0

I want to count how many times each user has rows within ‘5’ of eachother.

For example, Don – 501 and Don – 504 should be counted, while Don – 501 and Don – 1600 should not be counted.

Start:

Name        value
_________   ______________
Don         1235
Don         6012
Don         6014
Don         6300
James       9000
James       9502
James       9600
Sarah       1110
Sarah       1111
Sarah       1112
Sarah       1500
Becca       0500
Becca       0508
Becca       0709

Finish:

Name            difference_5
__________      _____________
Don             1
James           0
Sarah           2
Becca           0
  • 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-08T20:47:41+00:00Added an answer on June 8, 2026 at 8:47 pm

    Use the ABS() function, in conjunction with a self-join in a subquery:

    So, something like:

    SELECT name, COUNT(*) / 2 AS difference_5
    FROM (
      SELECT a.name name, ABS(a.value - b.value) 
      FROM  tbl a JOIN tbl b USING(name)
      WHERE ABS(a.value - b.value) BETWEEN 1 AND 5
    ) AS t GROUP BY name
    

    edited as per Andreas’ comment.

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

Sidebar

Related Questions

I want to count how many times i built on VS.NET . I have
i have a table which has many fields but i want to get count
I want to count how many members of an iterable meet a given condition.
We want to count number of shakes done by user. We tried motionBegan, motionEnded
I want to count the rows in several date ranges (i.e: last hour, today,
I have two tables of concern here: users and race_weeks. User has many race_weeks,
I'm hoping to count how many times a pointer is being used. I have
I want to make a summary script, for example, how many new users are
I want to count number of files in a folder in a remote host.
I want to count the numbers of hard tab characters in my documents in

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.