Merge Two Rows of a table to One row but into two columns
Hi
I Am struck in writing a query to merge two rows into two columns of one row.
Here is the Sample data i am working with,
Col 1 Col 2 Col3 Col4 Col Col6
5000 573-3000 2 0 Phone
5000 573-3036 1 0 Fax
5000 893-5703 3 0 WOrk
3000 232-5656 1 0 Phone
3000 353-5656 2 0 FAx
Here Col,Col3,Col4 form the Key.
now wht i am trying to do is to Merge these type of rows put them into Columns P,F,W,E respectively to achive a Structure as below
Col1 P F W
5000 573-3000 573-3036 893-5703
3000 232-5656 353-5656
Can you please help me how could i do this.
I am pretty ordinary at writing SQL's.
Thanks a Lot in Advance
Message was edited by:
Sreebhushan
Search the forum for PIVOT and you'll find plenty of examples.
Similar Messages
-
Merging rows into one row but into SEPARATE Columns
Hello Gurus,
I have searched alot on OTN and many other places, but no where I could get the solution of how can we merge rows into one row but separate column. For example
Consider the below scenario
"DEPARTMENT", "EMP","NAME","SUBJECT"
"Electronics","1","Sam","LIC"
"Electronics","2","Pam","VLSI"
"Electronics","3","Tom","C"
"Mech","1","Abu","Thermo"
"Mech","4","Lina","Machines"Now, I need the output like
Based on Department as Group By Clause
"DEPARTMENT", "EMP1","NAME1","SUBJECT1","EMP2","NAME2","SUBJECT2","EMP3","NAME3","SUBJECT3"
"Electronics","1","Sam","LIC","2","Pam","VLSI","3","Tom","C"
"Mech","1","Abu","Thermo","4","Lina","Machines"
The row data to be loaded into separate columns. Name of the column is not an issue... can be anythingIn all the forums which I went through I could find them loading into a single column, but not into respective separate columns.
Any help would be much appreciated.
Thanks848265 wrote:
Frank,
I saw your name nearly n number of times, as I went through many forums today... And the link which you have just posted, I went through it today afternoon.
Could you please explain this bit taken from your dynamic pivot post.
SELECT DISTINCT
', COUNT (CASE WHEN job = '''
|| job
|| ''' ' AS txt1
, 'THEN 1 END) AS '
|| job
|| '_CNT' AS txt2
FROM scott.emp
ORDER BY txt1;Many Thanks.You only need that when you need column aliases based on the actual data (and you explicitly said you don't need that) or when can't put an upper bound on the number of columns to be displayed. If that doesn't apply to this problem, then don't use any kind of dynamic SQL (like the code above); it makes the job much more difficult, less efficient and less robust.
Here's what the code above is doing.
If you were hard-coding a query that showed the number of people in each job, and you knew that the possible jobs were 'ANALYST', 'CLERK' and 'MANAGER', then you might hard-code a query like this:
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager
FROM scott.emp
GROUP BY deptno
;If the jobs had different names, or if there were not 3 different jobs, then you would have to change the lines in the SELECT clause that start with ", COUNT ( CASE ...".
The code you posted is from an example of dynamic SQL, where you first run a Preliminary Query . (What you posted above is, in fact, the complete preliminary query.) The output of that preliminary query is exactly the variable part of the real query, such as:
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS managerYou then use this output as part of your main query. In other words, you can write something today that will generate exacrly as many columns as you need next year, with names from the data as it is next year. How? because you're not writing the full query today. The variable part will be written by the preliminary query when it runs next year. -
Merging two columns with muliple rows in Numbers '09
I am trying to merge two columns each with 100 rows and related data. Column one is the street address and column two have office numbers. The final result would be one column with 100 rows with address and office numbers.
Ed Carreonsanpanza wrote:
I am trying to merge two columns each with 100 rows and related data. Column one is the street address and column two have office numbers. The final result would be one column with 100 rows with address and office numbers.
Ed Carreon
Hi Ed,
Use the CONCATENATE() function.
Street address in column D, Office number in Column E
100 Smith ST 212
Formula: =CONCATENATE(E," ",D)
Result:
212 100 Smith ST
Note the formula has three arguments, the reference to column E, a text literal (" ") containing a single space, and a reference to column D.
Regards,
Barry -
How to merge two columns in WAD(column chart)
Dear Experts,
Please provide your valuable suggestion to get a merge two columns in one column WAD column chart.
Example: we are having 3 fields (Budgeted value, Actual budgeted value & non budgeted value).
In the chart to be shown, budgeted value in one column, remaining two to be merged in one column
In below sample image Actual(Volume) column is having twe fields (Budgeted SKU value & Non budgeted SKU),
please provide solution to get same in SAP BI/BW WAD.
Thanks & Regards,
Sudarsan Reddy.Hi..,
With in the internal table structure you can declare one more field like NAME(30).
And concate nate first name and last name into that NAME field of internal table and modify the internal table
Now display this field..
Thanks,
Naveen.I -
Display TextBox Merging two columns
hi
In a Form i want to display textbox merging two columns
when i increading the width of textbox , elements(textbox,selectlist) in the column 2 move right sideEdit your item and go to
Displayed > ColSpan
and increase it to two or three...
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
How to merge two columns in csv file using vbscript?
How i can merge two column in csv file using vbscript or powershell?
1 , 2 , 3 , 4 , 5
1 , 23 , 4 , 5
thanksHere are two examples
http://msdn.microsoft.com/en-us/library/ms191250.aspx
calulated
http://msdn.microsoft.com/en-us/library/ms191250.aspx
Gary Newman MCSE, MCT, CCNA, MCSD, MCPD, MCDBA, MCAD, MCSA, MCTS Developer and Administrator On SharePoint 2013 SharePoint Practice Manager for AmeriTeach Denver, CO. -
Merging 2 rows data into a single column in OBIEE
Hi All,
Requirement is "Merging 2 rows into a single column"
Scenario: data from table called "transactions_table"
Id
transaction no
transaction name -------------------------------quantity
100
1
abc
1000
100
2
def
2000
Required out put:
Id
Transactions & Quantity
100
abc(1000),def(2000)
Please provide me solution, and let me know if any additional information is required.
Thanks in advance to all of you.can you please share your data like below
column1, column2 .....
and where are you trying to do this? at answer or bi admin tool?
there are a few ways to do this. -
Merging 2 rows data into a single column in OBIEE 11g
Hi All,
Requirement is "Merging 2 rows into a single column"
Scenario: data from table called *"transactions_table"*
Id ------------- transaction no ----------------------- transaction name -------------------------------quantity
100 ----------- 1 ----------------------- abc ------------------------------ 1000
100 ----------- 2 ------------------------ def ------------------------------ 2000
Required out put:
Id ----------------- Transactions & Quantity
100 -------------- abc(1000),def(2000)
Please provide me solution, and let me know if any additional information is required.
Thanks in advance to all of you.
Regards,
chrscheck the below link, that may help you.
Re: Horizontal value display
If it is helpful, please mark as correct or helpful -
Hi Experts,
I have a requirement, and I need to merge the the two columns in ALV. How can I do this?
Points will be rewarded for helpful answers.
Thanks in advance...Hi Salem
Check this sample code
LOOP AT itab.
CONCATENATE itab-amount itab-currency INTO itab-combined.
MODIFY itab.
ENDLOOP.
You will probably need to embellish just that concat command as all fields will be treated as TYPE C.
Then inhibit the display of the original fields amount and currency by setting NO_OUT=X in the fieldcat loop (or other method).
There may be a FM to merge/format amounts and currency but I couldnt find one on quick search.
The option 'USING EDIT MASK' from WRITE command is also available in ALV structure IT_FIELDCAT.
I have only used it in write and for simple stuff, but it may have some options for you.
Check '==conv' for output conversion routine...
Reward all helpfull answers
Regards
Pavan -
How to fetch single row data into multiple columns
Hi Have a cursor
which will have SELECT Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs from OTMaster;
now my cursor has one row of the above columns with this row data I want to insert into other tale as column wise
ex:
my row is like this: Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs
01:00 01:00 01:00 01:00 01:00 01:00 01:00
now I want to insert the above data into table with loop along with weekday
weekday, OTHrs
1 01:00
2 01:00
3 01:00
4 01:00
5 01:00
6 01:00
7 01:00
which type of variable I need to fetch the records, rowtype or tabletype,
plz help methank you for information, and now I am using UNPIVOT below is my query
SELECT * FROM OTCEILINGMASTER
UNPIVOT(OTHOURS FOR WEEK_DAY IN (SUN_CEILING_HRS AS '1',MON_CEILING_HRS AS '2',TUE_CEILING_HRS AS '3',
WED_CEILING_HRS AS '4',THU_CEILING_HRS AS '5',FRI_CEILING_HRS AS '6',SAT_CEILING_HRS AS '7'));
when I am selecting all the columns (select * from OTCEILINGMASTER) then only the above query is executing I want only two columns from the table however my table has 10 columns.
please looking into this -
Concatenate multiple row values into single column value
Hello,
Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
SELECT a.application_id, a.membership_number,
r.reason_text AS denial_reason,
a.appl_receipt_date AS application_receipt_date,
a.plan_request_1 AS application_plan_code,
a.adjudication_date AS application_denial_date
FROM application a, PLAN p, application_reason ar, reason r
WHERE a.plan_request_1 = p.plan_cd
AND a.application_id = ar.application_id
AND ar.reason_id = r.reason_id
AND a.adjudication_cd = 'D'
AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
AND p.plan_type_id = 12 and a.application_id = :appId
ORDER BY application_id
Any help is greatly appreciated.
Thanks,
-Christinefound the following
SELECT deptno,
LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM (SELECT deptno,
ename,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
FROM emp)
GROUP BY deptno
CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
START WITH curr = 1;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php -
Merge two column value in single column
Team,
I have a requirement where in I need to merge 2 column values in a single column.
ex. I have Percent_complete column in my table. and my table has only one record.
I need to query such that I need to store the values of percent_complete and (100- percent_complete) values in a single column.
ex
Percent complete has 30 value.
I need to select 30 and 70(100-30) both in a single column.
Thanks,SQL> select *
2 from tbl
3 /
PERCENT_COMPLETE
30
SQL> select abs(grouping(1) * 100 - max(percent_complete)) percent_complete
2 from tbl
3 group by rollup(1)
4 /
PERCENT_COMPLETE
30
70
SQL> select nvl(percent_complete,100 - max(percent_complete)) percent_complete
2 from tbl
3 group by rollup(percent_complete)
4 /
PERCENT_COMPLETE
30
70
SQL>
SY. -
I Have just spent the best part of a week installing iTunes on my laptop, transferring over all my music and merging tracks by different artists on one album so that they all show as one album. I have just plugged in my new ipod classic to sync all my music but the music has gone across in random tracks and split albums.... I really am losing the will to live and am about to throw both iPod and laptop out the window.... So SOMEBODY.... Please HELP.
'The installer has insufficient privileges to modify this file C:\Program Files (x86)\Common Files\Apple\Apple Application Support\Web kit.resources\inspector\Images\Spinner Inactive Selected.gif.'
That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
XP instructions in the following document: How to perform disk error checking in Windows XP
Vista instructions in the following document: Check your hard disk for errors
Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards? -
Merge Two Columns in a Single Column
Dear,
Inputs
Table1 |
Col1 (Number) |
1 |
2 |
3 |
4 |
5 |
6 |
and table 2
Table2 |
Col1 (Number) |
7 |
8 |
9 |
10 |
11 |
12 |
No relation between the two tables
I want to write a select statement that will result
Column
1
2
3
4
5
6
7
8
9
10
11
12
No sorting is required, I just need to have all the values listed in a single column... How can I do?
Thanks in Advance.If there is dup values between the two tables and you want get only unique, use UNION. If not UNION ALL as already stated.
Nicolas. -
Merge two columns of url/text and locator numbers
Want to merge a url - http://www.vimeo.com to a numbered vimeo film locator for the 'screeners sheet' for a film contest.
The current set up is: Column A - film title; Column B will be the Category; Column C - the url of vimeo with a / at the end to accept...Column D - the vimeo film locator number; Columns E-I will be the rating topics (originality, technical accuracy etc); Column J will contain the sum of the screeners ratings from Columns E-I.
There is no need to have totals at the bottom of columns just at the end of the rows. We have about 1000 films being rated for the Contest to win over $30k in Awards (sweet!). Ultimately this list will be divided into Categories then 'shared' with the individual screening teams to view remotely through this spread sheet and rate the film work.
Oh the coup de gras is the merge needs to keep it as an active link to Vimeo (which doesn't happen in the =Concatenate(C,D) formula. The lyper link stays active when we manually input each letter/number - but for 1,000 films - that's a yikes amount of work. Gotta be an easier way!
Thanks for your help!
Possible Futures Film Contest
Programming Team
May 29Might need the mystics as well!
I'm having difficulty getting Numbers to recognize URLs to begin with, not just when they've been put together with the concatenation function (or the concatenation operator). I do have the feature turned on, but the recognition has been sporadic, to say the least.
Assuming you have that sorted out, this might be a profitable line of enquiry:
After joining the items using concatenation, select the cells now containing the full URL and Copy, then go to the Edit menu and choose Paste Values.
Can't test it myself, for the reasons given above, but the labor cost of the home test isn't unendurable.
Regards,
Barry
Maybe you are looking for
-
OS 8.6 Won't Boot login, etc.
I'm pretty well versed with OS X and Unix, but troubleshooting Mac OS 9 and below leaves me confused at times. I'm hoping someone knows what this means here. I've received a Grape iMac G3 (probably a Rev. C) that looks like it boots up fine, and the
-
Hi - I am typing information into a Adobe document which was created by another user. I would like to change the font size for the field so the complete entry can be viewed. I have Adobe Acrobat Standard version 9 and my operating systems is Window
-
Wireless Headset Motorokr S9/Sony DR-BT22 SUCCESSFULLY Paired!
I have SUCCESSFULLY paired both my Motorokr S9 and Sony DR-BT22 Wireless Headset to my iPhone! It can be done. You'll need the stereo transmitter adapter *SONY TMR-BT8iP*. Plug it to iPhone, it will say THIS ACCESSORY IS NOT MADE TO WORK WITH IPHONE,
-
Error - when creating a standby database with EM 10g Grid Control
Hi, I am experiencing some problems when I want to create through the EM 10g Grid Control a standby database from a allready existing db. At step 2 when the files should be generated and copied to the other system, I am always getting the error that
-
Mail button is stuck. Wont launch ...... pinwheel spins and spins ..... any suggestions