How to display rows of data into different columns?
I'm new to SQL and currently this is what I'm trying to do:
Display multiple rows of data into different columns within the same row
I have a table like this:
CREATE TABLE TRIPLEG(
T# NUMBER(10) NOT NULL,
LEG# NUMBER(2) NOT NULL,
DEPARTURE VARCHAR(30) NOT NULL,
DESTINATION VARCHAR(30) NOT NULL,
CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (T#, LEG#),
CONSTRAINT TRIPLEG_UNIQUE UNIQUE(T#, DEPARTURE, DESTINATION),
CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (T#) REFERENCES TRIP(T#) );
INSERT INTO TRIPLEG VALUES( 1, 1, 'Sydney', 'Melbourne');
INSERT INTO TRIPLEG VALUES( 1, 2, 'Melbourne', 'Adelaide');
The result should be something like this:
> T# | ORIGIN | DESTINATION1 | DESTINATION2
> 1 | SYDNEY | MELBORUNE | ADELAIDE
The query should include the `COUNT(T#) < 3` since I only need to display the records less than 3. How can I achieve the results that I want using relational views???
Thanks!!!
T#
LEG#
DEPARTURE
DESTINATION
1
1
Sydney
Melbourne
1
2
Melbourne
Adelaide
1
3
Adelaide
India
1
4
India
Dubai
2
1
India
UAE
2
2
UAE
Germany
2
3
Germany
USA
On 11gr2, you may use this :
SELECT t#,
REGEXP_REPLACE (
LISTAGG (departure || '->' || destination, ' ')
WITHIN GROUP (ORDER BY t#, leg#),
'([^ ]+) \1+',
'\1')
FROM tripleg
where leg#<=3
GROUP BY t#;
Output:
1 Sydney->Melbourne->Adelaide->India
2 India->UAE->Germany->USA
Cheers,
Manik.
Similar Messages
-
How to display the header data on different position in alv report
hi all,
how to display the header data on different position in alv report.
for example ,
customer name
xxxx xxxx
vendor name street
xxxx xxxx xxxxx
pls help me .hi
as per my understanding you need to trnasfer header internal table data to pdf..
please check the following links for internal table to pdf..
Convertion of Internal table data to PDF
This link is related to ur issue
Re: how to insert the calling of the FM: OTF to PDF
Thanks -
How to display rows of data in JSP?
Hi,
I am learning Servlet and JSP. There is an exercise which requires us to access a database from a Servlet and display the retrieved data in a JSP.
Now I am ok with the database connection. So how to display the data using some kind of loop?
RegardsThey're called ResultSets and they are returned when you execute a query from a Statement. The next() method will tell you whether or not you have another row of data to read.
-
How to break range of dates into different months in mm/yyyy format
See the following eg:
MaterialNo Validfrom ValidTo RecordNo Value
A100 01.01.2007 13.05.2007 1000 1150/-
14.05.2007 24.08.2007 1001 1550/-
Now I want to break these dates into mm/yyyy format based on a condition. If the date(day) 15th lies in the range of dates
then it should pick that Value.
The output should be in this format.
MaterialNo Validfrom ValidTo Date RecordNo Value
A100 01.01.2007 13.05.2007 012007 1000 1150/-
022007 1000 1150/-
032007 1000 1150/-
042007 1000 1150/-
A100 14.05.2007 24.08.2007 052007 1001 1550/-
062007 1001 1550/-
072007 1001 1550/-
082007 1001 1550/-Hi Shiva,
In your Report Program, you can define the field of type sy-datum. And then fill the fields with the date. And then you can extract the rest of it manually by this small and simple lines of code. Once you have the date extracting logic then you can output the date in any manner according to your wish.
data : lv_date TYPE sy-datum.
data : lv_month TYPE c LENGTH 2.
data : lv_year TYPE c LENGTH 4.
data : lv_month_year TYPE c LENGTH 6.
lv_date = sy-datum.
lv_month = lv_date+4(2).
lv_year = lv_date+0(4).
CONCATENATE lv_month lv_year INTO lv_month_year.
Hope this helps.
Thanks,
Samantak. -
Changing rows into different column names
Hi,
i need to tranpose the rows into differnent column names
my sample data :
id , val
1 3
1 4
1 5
into
id , val1, val2 , val3 , val4 ... valn ..
1 3 4 5
from askTom's i see that it's tranpose into a single column using the ref cursor ?
how can i do made it into different column names ?
kindly advise
tks & rdgsFor example, lets say that you want to order your columns from least value to greatest and that you'll never have more than three values per id. Then you can use the analytic function row_number() like this to create a pivot value.
select id, val,
row_number() over (partition by id order by val) as rn
from your_table;And so your pivot query ends up looking like this.
select id,
max(case when rn=1 then val end) AS val1,
max(case when rn=2 then val end) AS val2,
max(case when rn=3 then val end) AS val3
from (
select id, val,
row_number() over (partition by id order by val) as rn
from your_table
group by id;But notice that I started out by making up answers to Justin's questions. You'll have to supply the real answers. -
JTable: HOW TO INSERT ROWS AND DATA?
I have one JFrame on screen and inside of this i have a JTable, the question is how to insert rows and data into the JTable?
[http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]
In future, please post Swing questions to the [Swing Forum.|http://forums.sun.com/forum.jspa?forumID=57]
In short, your TableModel is probably a DefaultTableModel . Study its API. -
Can we send the data into different data target from single datasource how
Hai
can we send the data into different data target from single datasource how ?Hi,
Create the transformation for each target and connect through DTP if you are in BI 7.0
If it is BW 3.5 create transfer rules and load it Info source and then different update rules for different targets then load it using IP.
If you are speaking about loading data from R3 data source to multiple data sources in BI
Then follow the below step.
1)create init IP's and run the IP's with different selection to different DSO(With same selection it is not possible).
2)Then you will have different delta queues for the same data source in RSA7
3)Your delta loads will run fine to different data sources from same DS in R3.
Hope this helps
Regards,
Venkatesh -
Not able to display data in different columns using Unicode encoding
Hi,
Iam using Unicode encoding in my Java appln to support Japanese characters while downloading CSV report. But using the Unicode encoding displays all data in the first column of Excel sheet.
Please let me know how to display data in different columns using Unicode encoding in Excel sheet.Hi Venkat,
After extracting data into DSO check the request whether active or not.
Check data in DSO in contents.
If is there any restrictions on info providers in Queries.
Let us know status clearly.......
Reg
Pra -
SegregatingTable data into different bucket with equal numebr of
Hi Guys,
I wanted to process table data in chunks not all the rows at a time. How can we achieve this in oracle.
Example :
I have one table EMP which has ten thousands rows(10,000) rows. Now these ten thousands rows are joined with other tables to process data and it takes time. So I wanted to pass one thousands rows at a time as an input to the procedures so that processing should happen only with 1 thousands rows at a time. This table does not have any primary key. So it there any method in oracle using that I can segregating the tables data into different buckets with equal number of rows.
I have used DBMS_PARALLEL_EXECUTE but its taking lots of time. Any help will be appreciated.I have one table EMP which has ten thousands rows(10,000) rows. Now these ten thousands rows are joined with other tables to process data and it takes time.
OK... So this is your actual problem. And the solution you are trying to come up with does not sound promising. So lets take a step back and re-think our strategy here. First thing would be how about we see some code? Show us your code that you say is running slow. And we can take it from there. The number 10,000 is a very small number. And if that is causing performance issue then you are in some big trouble.
And also it wouldn't hurt if you could read this Re: 3. How to improve the performance of my query? / My query is running slow. -
Copy a certain row of data into the next row in a same internal table ??
HI, guys.
May i know how to copy a certain row of data into the next row in a same internal table ?? Bcz I plan to update a certain colum of data in the row just now into another value..
For example:-
*at first...
ebeln1 ebelp1 xblnr1
ebeln2 ebelp2 xblnr2
ebeln3 ebelp3 xblnr3
*after that, become...
ebeln1 ebelp1 xblnr1
ebeln2 ebelp2 xblnr2
ebeln2 ebelp2 xblnr4
ebeln2 ebelp2 xblnr5
ebeln3 ebelp3 xblnr3
Thanks in advance.hi,
If you have this kind of requirement then you must be having 2 internal tables ,one existing data and 2nd from which you have to insert the records into 1st table.
so in this case,
loop at itab1.
v_index = sy-tabix.
loop at itab2 into wa where pri_key = itab1-pri_key.
v_index = v_index + 1.
insert wa into itab index v_index.
endloop.
endloop.
Using this code ,your data records similar to your 1st tables primary key records will get inserted into table. -
How to display and edit the clob datatype column from Data base
Hi ,
I have a requiremsnt as below
1) One Table having some columns with CLOB data type along with varchar columns
2) need to display the data from DB in search screen and need to be edited clob column in edit screen
I created EO and VO with that Table and how to display the clob value into the input box for editing.
using Jdev 11.1.1.5.0 version.
Can you please help on this.
THanks & REgards,
MadhuHi,
If you are using an inputText component to display a Character Large Object (CLOB), then you will need to create a custom converter that converts the CLOB to a String.
For custom convertor refer below link,
http://docs.oracle.com/cd/E2438201/web.1112/e16181/af_validate.htm#BABGIEDH
(section7.4 Creating Custom JSF Converters)
Thanks,
Santosh M E -
Split data into different fields in TR
I have a flat file with space (multiple spaces between different fields) as a delimiter. The problem is, file is coming from 3rd party and they don't want to change the separator as comma or tab delimited CSV file. I have to load data in ODS (BW 3x).
Now I am thinking to load line by line and then split data into different objects in Transfer rules.
The Records looks like:
*009785499 ssss BC sssss 2988 ssss 244 sss 772 sss 200
*000000033 ssss AB ssss 0 ssss 0 ssss 0 ssss 0
*000004533 ssss EE ssss 8 ssss 3 ssss 2 ssss 4
s = space
Now I want data to split like:
Field1 = 009785499
Field2 = BC
Field3 = 2988
Field4 = 244
Field5 = 772
Field6 = 200
After 1st line load, go to 2nd line and split the data as above and so on. Could you help me with the code pleaseu2026?
Is it a good design to load data? Any other idea?
I appreciate your helps..Hi,
Not sure how efficient this is, but you can try an approach on the lines of this link /people/sap.user72/blog/2006/05/27/long-texts-in-sap-bw-modeling
Make your transfer structure in this format. Say the length of each line is 200 characters. Make the first field of the structure of length 200. That is, the length of Field1 in the Trans Struc will be 200.
The second field can be the length of Field2 as you need in your ODS, and similarly for Field3 to Field6. Load it as a CSV file. Since there are no commas, the entire line will enter into the first field of the Trans Structure. This can be broken up into individual fields in the Transfer Rules.
Now, in your Start Routine of transfer rules, write code like this (similar to the ex in the blog):
Field-symbols <fs> type transfer-structure.
Loop at Datapak assigning <fs>.
split <fs>-Field1 at 'ssss' into <fs>-field1 <fs>-field2 <fs>-field3....
modify datapak from <fs>
endloop.
Now you can assign Field1 of Trans Struc to Field1 of Comm Struc, Field2 of Trans Struc to Field2 of Comm Struc and so on.
Hope it helps!
Edited by: Suhas Karnik on Jun 17, 2008 10:28 PM -
How to display previously entered data in TableModel
This post is continued from the last one. I was having problem displaying previously entered data into TableModel. someone suggested whether my TableModel is persistent.
I am sorry to say I am not sure how to make TableModel persistent. Can someone tell me what to do.
Following is my implementation of TableModel:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
public class UsersModel implements TableModel {
public static final String[] colNames ={
"Usernmae",
"Location"
public static final Class[] colClasses ={
String.class,
String.class,
public static final int
USERNAME_COL = 0,
LOCATION_COL = 1;
//used to hold a list of TableModelListeners
protected java.util.List tableModelListeners = new ArrayList();
protected java.util.List data = new ArrayList();
public static void main(String []args){
new UsersModel();
}//end main
public UsersModel(){
public void add(Users u){
data.add(u);
and when I need to add new users, I do it in the following way:
Users u= new Users(n,l);
model.add(u);
table.setModel(model);
I hope someone can helpPlease post the entire class, this certainly won't compile because it does not implement all the TableModel methods. Also, why not base it off of AbstractTableModel?
-
Displaying metadata, how to display ONLY the Date
I would like to display the Date below each image in Aperture 3. When I select "Date" in the Browser & Viewer Metadata window, the result is a very long string with the Date, the Time and the Time Zone. meaning that most of the time I see nothing because the string is much too long to be displayed...
How to display ONLY the Date ?
Thank you.
Olivierom28 wrote:
I will do that but still... if the Date could be ONLY the Date "without time and time zone", I would be able to display more information.. and it will look nicer.
I said at the top of my first response above: +Afaik, there is no way within Aperture to change the date format of the date metadata overlay.+
Send Aperture feedback to Apple via "Aperture→Provide Aperture Feedback"
In the past I used Expression Media and the config for displaying such info was better.
Aperture has a strange interface for it (and for other parameters), it does not behave at all like an Apple software (for the GUI), probably an external development team... but I agree it is more complex than iPhoto.
Aperture is 10x more complex than iPhoto.
If you want to see a rigid, boxed, "engineer"-style image database interface, take a look at Lightroom 3. It's a great program -- but it's a very different concept of information presentation and interaction.
Thanks again. -
How to display smartforms table lines useing different background colour
Hi all:
How to display smartforms table lines useing different background colour .
for example:
line1:green
line2:red
line3:green
line4:red
line5:green
line6:red
line7:green
line8:red
Any help is highly appreciated!!
启明星Hi,
Create a two lines one for header and second for data in the table.
1)In table painter we can find the pencil mark.
2)select the pencil mark
3)now select the line which you need to shade
4) now select the shading colour in the table painter and the provide the resolution up to 100% and select table pattrn for that line.
5) Now you can use this for the header now only the header gets shaded and the remaining gets unshaded.
reward points if useful
Thanks and Regards,
Nishant
Maybe you are looking for
-
iTunes starts to download and the pop-up asking to allow Apple Inc. to make changes to the hardrive comes up but the installer then says "The installer encountered errors before iTunes could be configured. Errors occured during installation. Your sys
-
How safe is this website?
Is this a safe web site to download apps Macupdate??
-
Need help installing CS5 on my Macbook Air i5 with Lion OS?
I am not sure what I am doing wrong. I am trying to install CS5 on my new i5 macbook air which runs lion. When I connect my external hard drive to install the disc the disc does not even show up on the desktop. I know the drive is fine because I test
-
Check tax classification Customer creation (IDOC)
Hi all, I am a beginner in SAP Abap and i need some help to resolve my IDOC problem. I want to generate Customer migration. my segments for the IDOC are filled. I use the IDOC_INBOUND_WRITE_TO_DB to create my IDOCs. Also for some customers, an error
-
Save Link As/New Folder/Save/ Causes Firefox to crash
This was posted 11 months ago and was solved by creating a new user profile. http://support.mozilla.org/nl/questions/890781 Right-click a link and choose 'save link as...' Browse to desired location and click 'new folder' Name the folder and open it