Home » SQL & PL/SQL » SQL & PL/SQL » Put data from one field to another. (PLSQL)
Put data from one field to another. [message #671132] Thu, 16 August 2018 05:48 Go to next message
twardybidon
Messages: 2
Registered: August 2018
Junior Member
Good morning,
maybe someone can help me. This is just an example and I think it is the best way to "describe" my problem.
This is what I got. You can see it on the top of the attached file. I would like to receive the results as on the picture below. Fulfill columns C and D based on the results from first entry.
Thank you so much.
select t.a, t.b,t.c, t.d from tsu t where t.x = 100 and t.y = 7 order by 1;

PLSQL.
  • Attachment: test.png
    (Size: 32.31KB, Downloaded 1153 times)
Re: Put data from one field to another. [message #671138 is a reply to message #671132] Thu, 16 August 2018 07:02 Go to previous messageGo to next message
John Watson
Messages: 8922
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum. Please read the OraFAQ Forum Guide and How to use code tags and make your code easier to read

I am not at all sure I understand what you are saying. If you were to provide the CREATE TABLE statement and the INSERT statements then it might become clear.
However, I think you need something like this:
select 
a,
b,
(select c from tsu where a=(select min(a) from tsu)),
(select d from tsu where a=(select min(a) from tsu))
from tsu;

Re: Put data from one field to another. [message #671146 is a reply to message #671132] Thu, 16 August 2018 07:59 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

select a, b, max(c) over(), max(d) over() from tsu;

[Updated on: Thu, 16 August 2018 10:34]

Report message to a moderator

Re: Put data from one field to another. [message #671173 is a reply to message #671146] Thu, 16 August 2018 10:27 Go to previous messageGo to next message
twardybidon
Messages: 2
Registered: August 2018
Junior Member
Hi guys,
thanks for quick response and for the welcome message Smile. Back to the query, the thing is that I have more than just one entries like this in the table.
I uploaded the screenshot once again. On the left side is what I fetched from the db. On the right side is what I would like to see as a result.
As you can see the entries where IDCONTAINER is not null are connected with this field where IDCONTAINER is null but IDCONTAINER from previous row equals to IDTSU.
example:
IDCONTAINER in second row = 903000110, idtsu = 903000111, weight =0 and height =0
and this is connected with first row
idcontainer = 0, IDTSU = 903000110, weight = 172, height = 2150.
and these weights and heights I would like to see in linked fields.
https://image.ibb.co/moCfaz/weight_height.png


So max function is not in use here I think, because I've got around 3000 entries like this in that table.

[Updated on: Thu, 16 August 2018 10:27]

Report message to a moderator

Re: Put data from one field to another. [message #671175 is a reply to message #671173] Thu, 16 August 2018 10:29 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
We don't have your tables.
We don't have your data.
Therefore we can't write any SQL & test it for you.

Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read
Re: Put data from one field to another. [message #671180 is a reply to message #671173] Thu, 16 August 2018 10:34 Go to previous message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
The thing is that I have more than just one entries like this in the table.
The OVER clause of analytic functions has a PARTITION BY part which is made for this.

Previous Topic: failing in Creation of PL/SQL function
Next Topic: Teradata To Oracle MOD Function
Goto Forum:
  


Current Time: Thu Mar 28 14:26:19 CDT 2024