simple query... but could not

CREATE TABLE person_del
(
DNO VARCHAR2 (5).
place VARCHAR2 (10),
EU VARCHAR2 (10)
)

commit;

insert into person_del values('1','home','Y')

insert into person_del values('1','office','N')

insert into person_del values('1','other','Y')

insert into person_del values('2','office','Y')

insert into person_del values ('3', 'home', 'n')

insert into person_del values ('3 ', 'Office', 'Y')

insert into person_del values ('4 ', 'other', 'n')

insert into person_del values ('5', 'home', 'Y')

insert into person_del values ('6', 'home', 'n')

insert into person_del values ('6', 'Office', 'n')

insert into person_del values ('7', 'home', 'Y')

insert into person_del values ('7 ', 'Office', 'Y')

commit;

Select * from person_del

Select the dno, place, got,
-case when am = 'Y', and then 'Y '.
Another null
end as "won".
of person_del
where to put in ("home", "office")


I ran the query above, but the result is not what I wanted
The condition is as follows:
List Y in a new column "earned" for these dno who reached the place - home or office
If a = Y for the home place and GOT = N for the Office of the place, then only view this column where OBTAINED = Y
If a = N to the home place and GOT = Y for the Office of the place, and then view only this column where OBTAINED = Y
If both are N then list a any column
If the two are then all a fo the column in the list
The place else is not taken into account
The output should be dno and won the column

I know it's simple... but I couldn't do it and I need it in a few minutes
Can someone help me on this using the CASE statement or something that is not difficult to understand the ASAP?

Basically, the output of it should be as follows:

DNO has won
1. IS
3 8
2 8
8 4
6 N
7. THERE

What:

SQL> select dno
  2  ,      got won
  3  from ( select dno
  4         ,      got
  5         ,      row_number() over (partition by dno, got order by dno, got desc) cnt
  6         from   person_del t
  7         where  t.place in ('home', 'office')
  8       )
  9  where ( case
 10            when got = 'Y' and cnt = 1 then 1
 11            when got = 'N' and cnt = 2 then 1
 12          end
 13        ) = 1;

DNO   WON
----- ----------
1     Y
2     Y
3     Y
5     Y
6     N
7     Y

6 rows selected.

Tags: Database

Similar Questions

Maybe you are looking for

  • Toshiba Satellite S2410-303 is not BOOT problem

    Hello!..I haveToshiba Satellite S2410-303 NotebookP4 1700/256 / 30 G, 15XT, CDW, LMand had Windows XP home.I use my cell phone without a network.When I push the power on the laptop, it isNo not from Windows XP. I just see "contact tomorrow with TOSHI

  • Qosmio X 770-Crysis 2 fails and an eye glued

    I have a Qosmio X 770/00 X PSBY5A-00X01D When you play Crysis 2 with the new pack of DirectX11, 3D fails. An eye gets stuck (watch the same screen). Google results talk about updating the nVidia Driver, but it won't support Nvidia. Download of the up

  • DeskJet 2540: cartridges in Europe to the United States model Deskjet 2540

    I bought the Deskjet United States about 2 years ago and now moved to the Poland 2540. I just bought the catrirdges ink 301 which are supposed to work for this printer (I couldn't find the 61 cartirdges in Europe) and seems that it does not work. cou

  • standard with a state machine controls

    Hello I read with VISA to a serial device. I am writing for the series the start character and the device sends data. Now after reading the data, I want to stop sending in writing to the series a stop character. Separate loop is playing. I want to do

  • LaserJet 1018 - cannot print documents

    The printer has been connected to my router so it can be shared. He worked like that for a few months, but a few weeks ago, my wife said that she could not print word or pdf from his laptop (Win 7 32). She was able to print a test page so that she co