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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:51:38+00:00 2026-06-17T09:51:38+00:00

I have been reading many topics about filtering SQL queries, but none seems to

  • 0

I have been reading many topics about filtering SQL queries, but none seems to apply to my case, so I’m in need of a bit of help. I have the following data on a SQL table.

Date                    item     quantity moved   quantity in stock sequence

13-03-2012 16:51:00    xpto         2                      2           1 
13-03-2012 16:51:00    xpto        -2                      0           2
21-03-2012 15:31:21    zyx          4                      6           1
21-03-2012 16:20:11    zyx          6                      12          2
22-03-2012 12:51:12    zyx         -3                      9           1

So this is quantities moved in the warehouse, and the problem is on the first two rows which was a reception and return at the same time, because I’m trying to make a query which gives me the stock at a given time of all items. I use max(date) but i don’t get the right quantity on result.

  • 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-17T09:51:39+00:00Added an answer on June 17, 2026 at 9:51 am
    SELECT  item, qty_in_stock
    FROM    (
            SELECT  *,
                    ROW_NUMBER() OVER (PARTITION BY item ORDER BY item_date DESC, sequence DESC) rn
            FROM    mytable
            WHERE   item_date <= @date_of_stock
            ) q
    WHERE   rn = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading so many topics here about this, but I could not
I have been searching through the web and reading many posts, but none has
I have been reading in many SQL books and articles that selectivity is an
I have been reading many topics on this subject, a drop down menu which
I have been reading around about best practices when doing developing a website. But
I have been reading many of the topics from this search so I really
I have been reading many posts that describe my problem but I cannot find
I have been reading about model inheritances in django and have found that many
Have been reading about async and tasks and been attempting to convert the CopyFileEx
I have been reading about making ajax heavy applications more search engine friendly: https://developers.google.com/webmasters/ajax-crawling/docs/getting-started

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.