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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:31:57+00:00 2026-06-13T19:31:57+00:00

I have a table that contains information for player’s steps taken for any given

  • 0

I have a table that contains information for player’s steps taken for any given day, I want to get the 3 highest totals from the database, when the day before the day of the high total has a value added to it for that player. Since some players are not logging everyday, but rather lumping multiple days into one update.

Data Structure:

|---------------------------------------------------------------|
| id | player_id | steps | date       | submitted               |
|----|-----------|-------|------------|-------------------------|
| 1  | 16        | 5718  | 2012-09-06 | 2012-09-10 08:31:35.000 |
| 2  | 16        | 9837  | 2012-09-07 | 2012-09-10 08:31:17.000 |
| 3  | 16        | 10432 | 2012-09-09 | 2012-09-10 08:30:54.000 |
| 4  | 30        | 3973  | 2012-09-07 | 2012-09-10 09:34:42.000 |
| 5  | 30        | 7104  | 2012-09-08 | 2012-09-10 09:35:05.000 |
| 6  | 30        | 10916 | 2012-09-09 | 2012-09-10 09:35:29.000 |
| 7  | 9         | 6437  | 2012-09-07 | 2012-09-10 09:39:15.000 |
| 8  | 9         | 9032  | 2012-09-08 | 2012-09-10 09:40:02.000 |
|---------------------------------------------------------------|

So what I want to return are the rows:

|---------------------------------------------------------------|
| 6  | 30        | 10916 | 2012-09-09 | 2012-09-10 09:35:29.000 |
| 2  | 16        | 9837  | 2012-09-07 | 2012-09-10 08:31:17.000 |
| 8  | 9         | 9032  | 2012-09-08 | 2012-09-10 09:40:02.000 |
|---------------------------------------------------------------|

My query is currently:

SELECT TOP 3 p.name,
             player_id,
             steps,
             date
FROM   steppers_step_log
       JOIN steppers_players P
         ON player_id = P.id
ORDER  BY steps DESC 

Which does not take into account whether there is an entry for the date prior on the top 3 from steps, which with my query in its current form will return 10432, 10916, and 9837 as the top steps.

I am having trouble working out how to do the WHERE command to make sure that the previous day has an entry for that player_id and would appreciate any help in getting it working.

  • 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-13T19:31:59+00:00Added an answer on June 13, 2026 at 7:31 pm

    Something like this?

    SELECT TOP 3 p.name,
                 player_id,
                 steps,
                 date
    FROM   steppers_step_log
           JOIN steppers_players P
             ON player_id = P.id
    WHERE EXISTS
    (
       SELECT 1 FROM steppers_step_log ssp
       WHERE ssp.player_id = P.id
       AND date = DATEADD(day, -1, steppers_step_log.date)
    )
    ORDER  BY steps DESC 
    

    DATEADD (Transact-SQL)

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

Sidebar

Related Questions

I have a table that contains information on groups. There can be any number
I have a table (user) that contains user information. I have another table (userview)
I have two tables: a schedule table that contains information about how an employee
I have a jsp that contains a table with some information from db. I
I have a table in Oracle 10g that contains some information as follows: SQL>
Suppose that I have a database table that contains information on cities across the
I have a table that contains the following information date sales 2011-02-13 1 2011-02-13
I have a table that contains information pointing to files stored on a file
I have a table that contains information pointing to files stored on a file
I have a table with that contains information that I would like to show

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.