SQL query: I want to know how to filter data...

I want to filter these data

yearDATA_TYPEproduct_nameamount
20131Apple100
20131Mango200
20141Apple300
20141Mango150
20141banana250
20151Apple350
20152Apple300
20153Apple320
20152Mango400
20153Mango400
20153banana500

In each year and each product, I want to filter the data that has no data in data type 1

When he has not given in data of type 1, using data in data type 2.

and if he has not given data type 2, use the data in data of type 3.

This is the result I was expecting

yearDATA_TYPEproduct_nameamount
20152Mango400
20153banana500

Thanks for your help.

Or more simply...

SQL > ed
A written file afiedt.buf

1 with t (year, data_type, product_name, amount) as)
2 Select 2013, 1, 'apple', 100 double Union all
3 select 2013, 1, "mango", 200 double Union all


4 Select 2014, 1, 'apple', 300 double Union all
5 Select 2014, 1, "mango", 150 double Union all
6 select 2014, 1, 'banana', 250 double Union all
7 if he would choose 2015, 1, 'apple', 350 dual Union all
8 select 2015, 2, 'apple', 300 double Union all
9 select 2015, 3, 'apple', 320 double Union all
10. Select 2015, 2, "mango", 400 double Union all
11. Select 2015, 3, "mango", 400 double Union all
12. Select 2015, 3, 'banana', 500 double
13        )
14-
15 end of test data
16-
17 select year
18, max (data_type) keep (first order by data_type dense_rank) as data_type
19, product_name
20, max (amount) to keep (first order by data_type dense_rank) as the amount
21 t
Group 22 by product_name, year
23 * have max (data_type) Dungeon (first order by data_type dense_rank)! = 1
SQL > /.

YEAR AMOUNT DATA_TYPE PRODUCTION
---------- ---------- ------ ----------
2015 mango 2 400
2015 banana 3 500

2 selected lines.

Tags: Database

Similar Questions

Maybe you are looking for

  • iPhone6 the wifi button does not illuminate.  I want to download the new update.  I restarted the phone, my router is active.

    iPhone 6 with iOS9.3.4. WiFi button does not illuminate.  I rebooted the phone.  How can I make this button of the device?

  • message about spyware are found in the computer

    Hello Through my Safari I when I click on a link for my class assignment a message popped up and told me (with an automated voice message) it was spyware detected on my computer and I need to contact a 1-800 number to make my person information will

  • Help! ACL MASSIVE corruption

    It seemed to me have made a colossal mistake to set up my iMac. I split the drive HARD internal into two partitions: OS X = P1 P2 10.10.5, = OS X 10.7.5.  All updates applied Here is was I think I was wrong: I installed OS X Server 5 on the partition

  • Windows Server 2012 will not be installed

    The boot order is successful in starting from my DVD. It starts to load files. So if fails with an error: "Windows has encountered a problem communicating with a device connected to your computer." ... This is a new server. I get the same problem whe

  • Memory of my laptop?

    HP laptop 15 " Model: G56-129WM Product: XG598UA #ABA Series: [personal information] This computer currently has 3 gigabytes of ram. I would like to install more ram. I need to know how many ram slots available to add more ram and the type OF ram tha