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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:22:37+00:00 2026-06-10T04:22:37+00:00

i have a requirement with a below table. conditions:- 1> i have to take

  • 0

i have a requirement with a below table.

conditions:-
1> i have to take the avg of salaries clints, who has 1day date of birth gap.
2> if there are no nearest 1day dob’s gap between the gap between the clients, then no need to take that client into consideration.

please see the results.

Table:

ClientID    ClinetDOB's         Slaries
1           2012-03-14              300  
2           2012-04-11              400  
3           2012-05-09              200  
4           2012-06-06              400  
5           2012-07-30              600  
6           2012-08-14              1200  
7           2012-08-15              1800  
8           2012-08-17              1200  
9           2012-08-20              2400  
10          2012-08-21              1500  

Result Should looks LIKE this:-

ClientID    ClinetDOB's         AVG(Slaries)
7           2012-08-15              1500        --This avg of 1200,1800(because clientID's 6,7 have dob's have 1day gap)    
10          2012-08-20              1950        --This avg of 2400,1500(because clientID's 9,10 have dob's have 1day gap))

Please help.

Thank You In advance!

  • 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-10T04:22:39+00:00Added an answer on June 10, 2026 at 4:22 am

    A self-join will connect current record with all records having yesterday’s date. In this context group by allows many records having the same date to be counted. t1 needs to be accounted for separately, so the Salary is added afterwards, and count(*) is incremented to calculate average.

    Here is Sql Fiddle with example.

    select t1.ClientID, 
           t1.ClinetDOBs,
           (t1.Slaries + sum (t2.Slaries)) / (count (*) + 1) Avg_Slaries
      from table1 t1
     inner join table1 t2
        on t1.ClinetDOBs = dateadd(day, 1, t2.ClinetDOBs)
     group by t1.ClientID, 
           t1.ClinetDOBs,
           t1.Slaries
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have a table as given below RMG Date Value YA 11/02/2001 94 YB
I have one requirement as shown below : Suppose we have EMP table with
I have a simple requirement as mentioned below: A ListView or any control displays
I have a organization name table with the following structure given below: CREATE TABLE
Requirement : I have a piece of code similar to the code below. I
I have a requirement to create a dynamic table from an xml file similar
I have a positions table in SQL Server 2008R2 (definition below). In the system
Please have a look at the below SQL code. DECLARE @RET TABLE(OID BIGINT NOT
I have a requirement as mentioned below: table1 ------------------------ A B C D E

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.