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

  • Home
  • SEARCH
  • 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 8092909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:23:16+00:00 2026-06-05T20:23:16+00:00

I working on test tool, reporting for it. SO, there is a test hich

  • 0

I working on test tool, reporting for it.
SO, there is a test hich can be performed automatically several times per day. And In one report I need to show historical data per test (chart with Date and Number of test passed) and the number of passed tests for latest day.
Lef’t create model of this issue:

I have such data structure (simplified):

DECLARE @TestResults TABLE
(
    TestId INT,
    DateOfResult DATE,
    TestPassedCount INT
);

INSERT INTO @TestResults VALUES (1,DATEADD(day,-3,GETDATE()), 6);--This test passed 4 times  3 days ago
INSERT INTO @TestResults VALUES (1,DATEADD(day,-1,GETDATE()), 4); --This test passed 4 times yesterday
INSERT INTO @TestResults VALUES (1,GETDATE(), 5); --This test passed five times today

INSERT INTO @TestResults VALUES (2,DATEADD(day,-3,GETDATE()), 6);--This test passed 4 times  3 days ago
INSERT INTO @TestResults VALUES (2,DATEADD(day,-1,GETDATE()), 4); --This test passed 4 times yesterday

SELECT * FROM @TestResults;

Last select will return me a data set:

TestId   DateOfResult   TestPassedCount
1   2012-06-12             6
1   2012-06-14             4
1   2012-06-15             5
2   2012-06-12             6
2   2012-06-14             4

How can I also get with this query (in separate column) the number of passed tests for max available date? For example, for test with ID 1 I have data for 12,13,14 of June. So, in separate column I need to get 5 because on latest date (max(DateOfResults)) there is five passed tests?

I’m using SQL Server 2012.

Thank you!

Update: I foound the way:

SELECT SubQ.*, r.TestPassedCount  FROM (
    SELECT *, Max(t.DateOfResult) OVER (PARTITION BY t.TestId ORDER BY t.TestId) as MaxDate FROM @TestResults t 
) AS SubQ JOIN @TestResults r ON r.TestId = SubQ.TestId AND r.DateOfResult = SubQ.MaxDate

Now I need to apply it to the real queries 🙂
Are there any other ways to do?

  • 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-05T20:23:17+00:00Added an answer on June 5, 2026 at 8:23 pm

    I can’t execute your solution, maybe are missing something? I’m having this error (and I can’t figure why):

    Msg 102, Level 15, State 1, Line 16
    Incorrect syntax near 'order'.
    

    So, my version of the query is almost equal:

    SELECT t2.TestId, t2.DateOfResult ,t2.TestPassedCount FROM @TestResults t2
    INNER JOIN (
                SELECT t.TestId, MAX(t.DateOfResult) AS MaxDateOfResult from @TestResults t
                GROUP BY t.TestId ) groupedTests ON groupedTests.TestId = t2.TestId AND groupedTests.MaxDateOfResult = t2.DateOfResult
    ORDER BY t2.TestId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been tasked with converting some text log files from a test reporting tool
I am working on a .NET internal test tool at the moment. The tool
I want to load test the web application that we're working on? Can you
I'm trying to test Strace tool in Android Real device but I can't get
I am working on a tool that will test the server of a Silverlight
Tool that can be used to migrate (or even better..synchronize) test cases and bugs
Working on a QC integration tool and having trouble creating a test in the
I'm working on the LoadRunner Tool to perform a Performance Test of a Web
I have been working on test framework, which creates a new app domain to
i am newbie to mongoDB ,as i start working with test application (ASP.Net) found

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.