Find products purchased in different years

Hi team,

I have the following table structure and data of id product and purchased date

I need to get the products that were purchased in 1900 and 2000 only

create table product (Product_id number, Product_nm varchar2 (11), cust_pur_date varchar2 (11))

Insert into the product

(Product_ID, Product_NM, cust_pur_date)

Values

(1, 'oracle', "1900");

Insert into the product

(Product_ID, Product_NM, cust_pur_date)

Values

(1, 'oracle', '1950');

Insert into the product

(Product_ID, Product_NM, cust_pur_date)

Values

(1, 'oracle', '2000');

Insert into the product

(Product_ID, Product_NM, cust_pur_date)

Values

(2, "java", "1900");

Insert into the product

(Product_ID, Product_NM, cust_pur_date)

Values

(2, "java", "1950");

COMMIT;

I wrote the following query to obtain the required data. Could you please other solutions for this

select Product_ID,Product_NM,cust_pur_date,lead_date
from(
select Product_ID,Product_NM,cust_pur_date ,nvl(lead(cust_pur_date)over (order by Product_ID desc ),0) lead_date
from Product)
where cust_pur_date ='1900'
and lead_date ='2000'

products that have been purchased in 1900 and 2000 only

Select * from product where cust_pur_date = 1900 or cust_pur_date = 2000;

Above won't work, it will give the two Oracle & Java.

Try this one:

Select * from product p where cust_pur_date = 1900

and exists (select 1 of the product p1

where p1.product_id = p.product_id

and cust_pur_date = 2000);

Tags: Database

Similar Questions

Maybe you are looking for

  • How drag and drop a picture into a shape of the object?

    On my old Lion system that I used to be able to drag a picture from iphoto in the shape of the object open in Pages.  I can't be able to do more.  The system changed?  I tried to use Inspector (under help), but it won't let me access the file of the

  • How much RAM can I put?

    Can you tell me how many slots of RAM I have and what the MAX RAM amount I can spend on this machine? Thank you!

  • Features Windows Lab SMU-1082

    I work in the lab of Windows (so please don't give me all the answers Lab View). I have a utility Windows Lab that I support, and I'm doing work on the SMU-1082. We will control the SMU with a MXIe (SMU-8360) connected to a PC. One thing I want to do

  • Uninstalling Corel error 2753

    Original title: Corel uninstaller I'm trying to uninstall Cortel Suite chart 4, particularly the Corel Paint Shop Pro Photo.  Corel tell me to uninstall manually, but when I download their uninstall program, it does not work.  I tried to uninstall it

  • HP recovery new hdd

    I have a HP dv6 3260es Nightingale that came with his "original HARD drive. I recently bought a new hard drive 250 GB SSD and replaced the old HDD by this news. I kept the old HDD and placed in the CD/DVD slot. Now, I have 2 hard drives and no CD/DVD