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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:39:45+00:00 2026-05-30T05:39:45+00:00

A) When goods are sold, a table will record an O in column ID

  • 0

A) When goods are sold, a table will record an “O” in column ID & a “N” in column TYPE:-

SKU      ID  TYPE  NR
-------------------------
HAB1122  O   N     201211

B) When goods are returned, a table will record an “O” in column ID & a “R” in column TYPE:-

SKU      ID  TYPE  NR
-------------------------
HAB1122  O   R     201223

Scenario 1

Goods were sold & returned later. It was sold subsequently:-

SKU      ID  TYPE  NR
-------------------------
HAB1122  O   N     201211
HAB1122  O   R     201223
HAB1122  O   N     201245
HAB2233  O   N     201263
HAB3344  O   N     201303
HAB3344  O   R     201341

Using SQL:-

Select SKU, max(NR) 
from tableA
where SKU like ‘HAB%’ and ID = ‘O’
group by SKU

Results:-

SKU       NR
----------------
HAB1122   201245
HAB2233   201263
HAB3344   201341

This is the correct result as I wish to track down the last NR of the goods sold whether the goods are sold or returned.

If I wish to track down the last NR of goods with status sold only, the expected results should be:-

SKU      NR
---------------
HAB1122  201245
HAB2233  201263

HAB3344 is not considered as the goods are returned & not sold subsequently.

How should I change the SQL?

  • 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-05-30T05:39:46+00:00Added an answer on May 30, 2026 at 5:39 am

    Try this:

    select   SKU, max(NR)
    from     TABLEA T1
    where    SKU like 'HAB%' and ID = 'O'
    group by SKU
    having   max(NR) <> (select nvl(max(NR), 0)
                         from   TABLEA T2
                         where  T1.SKU = T2.SKU and T2.type = 'R');
    

    This is using Oracle. You didn’t indicate your system so the having may not work specifically on yours but an equivalent will.

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

Sidebar

Related Questions

This is what I tried but it fails: alter table goods add column `id`
We are developing a web application that will be sold to many clients. There
I have a table hall_products with products. Each product has a NAME, is sold
I am working on crawler, which will search for goods in e-shops. It's my
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there
I'm building ASP.NET MVC2 website that lets users store and analyze data about goods
Given an HTML string like: <span class=findme id=31313131313>The Goods</span> What kind of REGEX in
Good morning, I am the developer of a medium sized PDA application that will
It's quite simple to program just one product to get sold via my payment
I'm currently developing a program that will generate reports based upon lead data. My

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.