dbTalk Databases Forums  

SQL Problem

comp.databases.oracle comp.databases.oracle


Discuss SQL Problem in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David
 
Posts: n/a

Default SQL Problem - 07-15-2004 , 10:55 AM






Table A
Name Score
A 12
A 22
A 88
B 34
B 12
C 33
C 55


Table B

Name Score
A 12
NuLL 22
Null 88
B 34
Null 12
C 33
NUll 55

How can i create table b base on table a ?



Reply With Quote
  #2  
Old   
AK
 
Posts: n/a

Default Re: SQL Problem - 07-16-2004 , 01:30 PM






CASE WHEN ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY SCORE) = 1 THEN
NAME ELSE NULL END

Reply With Quote
  #3  
Old   
Odd Morten Sve?s
 
Posts: n/a

Default Re: SQL Problem - 07-18-2004 , 03:58 PM



ak_tiredofspam (AT) yahoo (DOT) com (AK) wrote in message news:<46e627da.0407161030.42e5e818 (AT) posting (DOT) google.com>...
Quote:
CASE WHEN ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY SCORE) = 1 THEN
NAME ELSE NULL END
Hi

Is can this be runn on Oracle? I would be pleased to know more about
this type of syntax.

In a traditionel but of cource cumbersome syntax the following will do
the trick. (Not tested, so it migth be some syntax errors)

insert into b
(name,score)
select decode(rowid ,minrowid, name , null)
, score
(select rowid
, name
, score
, (select min(rowid) from a a2 where a2.name = a1.name ) minrowid
from a a1)

But the simples would be to write an pl/sql prgram to solve this,
includinga cursor, a loop and a check if the name has changed.


Regards
Odd M


Reply With Quote
  #4  
Old   
AK
 
Posts: n/a

Default Re: SQL Problem - 07-19-2004 , 02:28 PM



Quote:
Is can this be runn on Oracle? I would be pleased to know more about
this type of syntax.

Yes, it runs on Oracle 9i. If you google 'OLAP functions', 'analytical
functions' you'll get a lot of useful links


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.