Multiple Rows Into One Column Field
Hi All,
Today I tried one query:
select wm_concat(ename) from emp
group by deptno;
I have a data that looks like this.
CLARK,KING,MILLER,SREE
JONES,FORD,ADAMS,SCOTT
ALLEN,MARTIN,BLAKE,TURNER,JAMES,WARD
Can someone help me to build an SQL command that would have the output as follows:
I need per column 3 values....
CLARK,KING,MILLER,
SREE,JONES,FORD,
ADAMS,SCOTT,ALLEN,
MARTIN,BLAKE,TURNER,
JAMES,WARD
StewAshton wrote:
That's funny, I don't get the same answer
Why do you think you should?
Besides, you're not the only one.
ENAMES
KING,BLAKE,CLARK
JONES,SCOTT,FORD
SMITH,ALLEN,WARD
MARTIN,TURNER,ADAMS
JAMES,MILLER
Regards
Etbin
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
It's from my APEX Workspace: first select from the emp table (not touched until now)
Message was edited by: Etbin
Similar Messages
-
Collecting data from multiple rows into one column
I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
"CORE 10.2.0.5.0 Production"
TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
CREATE TABLE "SKIP"."INGREDIENTS"
( "INGRED_ID" NUMBER,
"INGRED_NAME" VARCHAR2(20 BYTE),
"STORES" VARCHAR2(20 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGREDIENTS
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
CREATE TABLE "SKIP"."PRETZELS"
( "PRETZEL_ID" NUMBER,
"PRETZEL_NAME" VARCHAR2(20 BYTE),
"PRETZEL_DESC" VARCHAR2(100 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.PRETZELS
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
CREATE TABLE "SKIP"."INGRED_XREF"
( "PRETZEL_ID" NUMBER,
"INGRED_ID" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGRED_XREF
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
-- Constraints for Table INGRED_XREF
ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
{code}
Desired output (note how the ingredients are all listed in one column, separated by commas):
{code}
PRETZEL_ID PRETZEL_NAME PRETZEL_DESC INGREDIENTS
1 CLASSIC Classic knot pretzel SEA SALT, TABLE SALT, YEAST
2 THICK STICK Straight pretzel, abt 1/2" in dia TABLE_SALT, FLOUR, BEERSee the FAQ : {message:id=9360005}
Especially links concerning string aggregation. -
Trying to convert multiple rows into multipe columns within a single row
I am trying to convert data from multiple rows into multiple columns. Let me see if I can paint the picture for you.
Here is a sample of the table i am trying to read from:
Company Name Account
1 Sam 123
1 Sam 234
1 Joe 345
1 Sue 789
1 Sue 987
1 Sue 573
I am trying to put this into a View that would have the data represented as such:
Company Name Acct1 Acct2 Acct3 Acct4
1 Sam 123 234 <null> <null>
1 Joe 345 <null> <null> <null>
1 Sue 789 987 573 <null>
Many thanks in advance for your help!test@XE> --
test@XE> with t as (
2 select 1 as company, 'Sam' as name, 123 as account from dual union all
3 select 1, 'Sam', 234 from dual union all
4 select 1, 'Joe', 345 from dual union all
5 select 1, 'Sue', 789 from dual union all
6 select 1, 'Sue', 987 from dual union all
7 select 1, 'Sue', 573 from dual)
8 --
9 select company,
10 name,
11 max(case when rn = 1 then account else null end) as acct1,
12 max(case when rn = 2 then account else null end) as acct2,
13 max(case when rn = 3 then account else null end) as acct3,
14 max(case when rn = 4 then account else null end) as acct4
15 from (select company,
16 name,
17 account,
18 row_number() over (partition by company, name order by 1) as rn
19 from t)
20 group by company, name;
COMPANY NAM ACCT1 ACCT2 ACCT3 ACCT4
1 Joe 345
1 Sam 234 123
1 Sue 573 789 987
3 rows selected.
test@XE>
test@XE>isotope -
Combining multiple rows into one row
Hi all.
My most humble apology for this question but solutions in previous threads did not seem to help much.
Apparently, my account has not been verified and I am currently at home with no access to the SQL code so i can't post the actual code.
We have this (mockup) of code
Select S.C1, AViewSS.Study, AViewSS.SlotName, IST.TakenByDate, IST.ScannedByTime, SE.TimepointCalculation
From IST
INNER JOIN
AViewSS ON IST.GroupID = AViewSS.GroupID and
IST.SlotID = AViewSS.SlotID
INNER JOIN
S ON AViewSS.StudyID = S.StudyID
INNER JOIN
SE ON IST.Line = SE.Line and IST.SubLine = SE.SubLine and
AViewSS.ScheduleID = SE.ScheduleID
WHERE
(IST.GroupID = 92) and (IST.SlotID between 1791 and 1795)
and (AViewSS.VisitID = 137)
The query currently returns this result set
Col 1 Col 2 Taken Date Date 1 Date 2 Date 3
Scanned DateTime
Data Data 3/12/2015 3/12/2015 7:22
3/12/2015 7:22
Data Data 3/12/2015 3/12/2015 8:47
3/12/2015 8:47
Data Data 3/12/2015
3/12/2015 9:27 3/12/2015 9:27
Data Data 3/22/2015 3/22/2015 7:27
3/22/2015 7:27
Data Data 3/22/2015
Data Data 4/12/2015
Data Data 4/12/2015
Data Data 4/12/2015
You’ll notice that rows 1, 2, 3 are related as are rows 4, 5 and rows 6, 7, 8.
This is what we ultimately want to see given the results above.
In the report, rows 1, 2, 3 from the results should roll into one row with the ScannedByTimeStamp from each row returned by the query populating the appropriate report time column based on the value of a column in the row.
Col 1 Col 2 Taken Date Date 1 Date 2
Date 3
Data Data 3/12/2015 3/12/2015 7:22 3/12/2015 8:47 3/12/2015 9:27
Data Data 3/22/2015 3/22/2015 7:27
Data Data 4/12/2015
We would appreciate any guidance.Hi Duane,
The table and matrix data regions can display complex data relationships by including nested tables,matrices, lists, charts and gauges. Tables and matrices have a tabular layout and their data comes from a single dataset, built on a single data source. The
key diference between tables and matrices is that tables can include only row groups, where as matrices have row groups and columns groups.
All Code in this sample are downloadable from
this URL
create procedure spMultiple
as
begin
declare @Mytable table ([Col 1] varchar(20),[Col 2] varchar(20),[Taken Date] varchar(20),[Date 1] varchar(20),[Date 2] varchar(20),[Date 3] varchar(20))
Insert into @Mytable ([Col 1],[Col 2],[Taken Date],[Date 1],[Date 2],[Date 3])
select * from
Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'3/12/2015 7:22' as [Date 1],'' as [Date 2],'' as [Date 3]
union all
Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'' as [Date 1],'3/12/2015 8:47' as [Date 2],'' as [Date 3]
union all
Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'3/12/2015 9:27' as [Date 3]
union all
select 'Data' as [Col 1],'Data' as [Col 2],'3/22/2015' as [Taken Date],'' as [Date 1],'3/22/2015 7:27' as [Date 2],'' as [Date 3]
union all
select 'Data' as [Col 1],'Data' as [Col 2],'3/22/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
union all
select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
union all
select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
union all
select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
) as temp;
with Mytable2(
[Col 1],
[Col 2],
[Taken Date],
[Date],
[NameDate]
as
SELECT
[Col 1],
[Col 2],
[Taken Date],
[Date],
[NameDate]
FROM
(SELECT
[Col 1],
[Col 2],
[Taken Date],
[Date 1],
[Date 2],
[Date 3]
FROM
@MyTable) as p
UNPIVOT
[Date] FOR [NameDate] IN ([Date 1],[Date 2],[Date 3])
)AS unpvt
group by
[Col 1],
[Col 2],
[Taken Date],
[Date],
[NameDate]
Select * from Mytable2 t1 where [date]<>''
end
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Ricardo Lacerda -
Hi friends,
I have one table like:
10 SAM
10 CAN
10 MAN
10 DEV
20 MAL
And want output like:
10 SAM,CAN,MAN,DEV
20 MAL
i want to combine multiple rows into one within an existing view.
What query will suit this to get this type of output.Please refer to this thread
column values separated by , -
SQL Query -How2bring multiple results into one field using Formatted Search
Hi Everyone
i am trying to bring in the results of the field dbo.Lot_ITEM.LOT using a formatted search into a row level using the following query:
SELECT dbo.LOT_ITEM.LOT
FROM dbo.DLN1 INNER JOIN dbo.LOT_ITEM ON dbo.DLN1.ItemCode = dbo.LOT_ITEM.ITEM
WHERE dbo.LOT_ITEM.ITEM=$[DLN1.ItemCode]
however the result of the dbo.Lot_ITEM.LOT field could be more then one value depending on how many lots are assigned for that item
(for example this query would be similar to assigning batch/serial numbers to an item being despatched - as you can choose multiple batches/serials depending on the quantities available and required and then move from the left to the right side of the selection window) if that makes sense!
is it possible to bring in the multiple results into one field? and how can i amend the above query to include this?
Thankyou in advance :o)
Edited by: Asma Bi on Apr 23, 2008 7:22 PM
Edited by: Asma Bi on Apr 23, 2008 7:24 PMHi Suda
Thanks for replying :o) but im not sure about the query?
just to simplify it (as the query im working with is to do with 3rd party addons) i have used the serial/batchs field instead and used standard demo database fields from SBO 2005 sp01:
SELECT dbo.ixvSerialNoFact.SRI1_IntrSerial
FROM dbo.DLN1 INNER JOIN
dbo.ixvSerialNoFact ON dbo.DLN1.DocEntry = dbo.ixvSerialNoFact.SRI1_BaseEntry
WHERE dbo.ixvSerialNoFact.ItemCode='g1000' and dbo.ixvSerialNoFact.SRI1_BaseEntry = '193'
The above brings me the relevant results but when i change it to be used in a formatted search:
SELECT dbo.ixvSerialNoFact.SRI1_IntrSerial
FROM dbo.DLN1 INNER JOIN
dbo.ixvSerialNoFact ON dbo.DLN1.DocEntry = dbo.ixvSerialNoFact.SRI1_BaseEntry
WHERE dbo.ixvSerialNoFact.ItemCode=$[dln1.itemcode] and dbo.ixvSerialNoFact.SRI1_BaseEntry = $[dln1.DocEntry]
i cant seem to get it to work - now this may be because the serial number is not allocated until teh record is added to the system, however when this happens i am unable to go back in and manually trigger the query as the delivery note rows cannot be selected!
i think as what im originally wanting an answer for is same as this example, im wanting to know if this is even possible?
Thanks
Edited by: Asma Bi on Apr 24, 2008 3:53 PM
Edited by: Asma Bi on Apr 24, 2008 3:55 PM -
BI for NW04S: Concatenating multiple chars into one field in BI query
Hi,
We have BI for NW04S. We have a requirement of concatenating multiple characteristics into one field in the BI report. This single field should have the usual drill down and other olap functionalities that a single characteristic usually enjoy in a BI report.
In BI for NW04 (Not the S) this probably can be done using the table interface in WAD. However in BI7 WAD functionality are through Java.
Also can this be done using Query designer alone.
Can anybody help?
ThanksHi,
Can you please elaborate on your Query designer option. You can always have a variable and in the user exit can write code, but what is not clear that
1> How will you acheive the contatenation done for every row of the report in the BEX user exit variable( since it's called during the beginning of the query execution and not for all rows of the report
2> How do you transfer the char variable into a char field in the report.
Please elaborate .
Thanks -
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
I wanted to display the multiple rows in one row but column should be diff
Hi
Could any body help me regarding this query how to write to get the multiple rows in one row.
eg.
i have one table tab1(eno number,ename varchar2,uid1 varchar2,uid2 varchar2,uid3 varchar4)
but when i am runing the query I am getting multiple record against one eno number because of uid1,uid2,uid3
suppose value of table is
eno ename uid1 uid2 uid3
1 a u1
1 a u2
1 a u3
when i am quering it is coming same as above but I want in one row
eno ename uid1 uid2 uid3
1 a u1 u2 u3
can any onle help me how to write the query for this requirement.
thanks
saifwhich is hard coded in my code? Here another approach, but fail for c as there is no information for the value of a column: does 1 in u1 means col 1, etc.
/* Formatted on 2012/05/29 16:29 (Formatter Plus v4.8.8) */
WITH t AS
(SELECT 1 col1, 'a' col2, 'u1' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'a' col2, 'u2' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'a' col2, 'u3' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'b' col2, 'u1' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'b' col2, 'u3' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'b' col2, 'u2' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'c' col2, 'u1' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'c' col2, 'u3' col3
FROM DUAL)
SELECT xx.col1, xx.col2, MAX (DECODE (xx.rn, 1, col3)) AS uid1, MAX (DECODE (xx.rn, 2, col3)) AS uid2,
MAX (DECODE (xx.rn, 3, col3)) AS uid3
FROM (SELECT t.col1, t.col2, t.col3, ROW_NUMBER () OVER (PARTITION BY col1, col2 ORDER BY col3) rn
FROM t) xx
GROUP BY col1, col2;output:
COL1 COL2 UID1 UID2 UID3
1 a u1 u2 u3
1 b u1 u2 u3
1 c u1 u3
Edited by: ʃʃp on May 29, 2012 2:30 AM -
Select One Choice-select multiple attributes into mutiple columns
Select One Choice-select multiple attributes into mutiple columns does not work.
read-only view object view1 - columns a, b, c
updatable view object view2 - also columns a, b, c
Select One choice has the capability to bind multiple columns to multiple columns. I understand how this wizard is to be used for these multiple mappings, i.e., view2.a mapped to view1.a, view2.b mapped to view1.b, etc., and using 'select multiple...' for the display attribute. When I complete the 'List Binding Editor" correctly, in this example, only column a will be updated. Columns b,c, etc. will not be effected.
Has anyone solved this? Please do not reply telling me how to use the editor, I know how, it just is not working.
Here is my jspx segment,
<af:selectOneChoice value="#{bindings.Eis000tv1SlOffice.inputValue}"
label="#{bindings.Eis000tv1SlOffice.label}">
<f:selectItems value="#{bindings.Eis000tv1SlOffice.items}"/>
Here is pageDef segment:
<list id="Eis000tv1SlOffice" IterBinding="Eis000tv1Iterator"
StaticList="false" ListOperMode="0" ListIter="OfficeSpaceV1Iterator"
NullValueFlag="1" NullValueId="Eis000tv1SlOffice_null">
<AttrNames>
<Item Value="SlOffice"/>
<Item Value="Floor"/>
<Item Value="FloorArea"/>
</AttrNames>
<ListAttrNames>
<Item Value="SlOffice"/>
<Item Value="Floor"/>
<Item Value="Area"/>
</ListAttrNames>
<ListDisplayAttrNames>
<Item Value="SlOffice"/>
<Item Value="Floor"/>
<Item Value="Area"/>
</ListDisplayAttrNames>
</list>
Here is the iterator:can u set as specified here
-Djps.app.credential.overwrite.allowed=true http://radalcove.com/blog/?p=34 -
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. -
Merge multiple rows into single row (but multiple columns)
How to merge multiple rows into single row (but multiple columns) efficiently.
For example
IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
23 asdc 1 Location USA NM ABQ Four Seasons 87106
23 asdc 1 Stats 2300 91.7 8.2 85432
23 asdc 1 Audit 1996 June 17 1200
65 affc 2 Location USA TX AUS Hilton 92305
65 affc 2 Stats 5510 42.7 46 9999
65 affc 2 Audit 1996 July 172 1100
where different attributes mean different thing for each Information_type.
For example for Information_Type=Location
Attribute_1 means Country
Attribute_2 means State and so on.
For example for Information_Type=Stats
Attribute_1 means Population
Attribute_2 means American Ethnicity percentage and so on.
I want to create a view that shows like below:
IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
ThanksHi,
That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
I hope this answers your question.
If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
Explain, using specific examples, how you get the results you want from the data given.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0). This is always important, but especially so with pivots.
See the forum FAQ {message:id=9360002} -
Inserting multiple selection from checkbox into one column of the database
Hi,
How to insert multiple selection values from checkbox into one column of the database.
Anyone can u help me
Thanxhi
try to use request.getParameterValues("fieldname") -
Select multiple column into one column
Hi..!!!
Is it possible to select 4 columns in to 1 columns?
I've major1, major 2, major 3, major 4 and i want to retrieve all the columns into one column called "Majors".
Is it possible? if yes then how?
Help me out.
Thanks,
HimadriIf you had given a proper example this thread would have been over in two posts. What you are looking for is often described as an UNPIVOT.
I tend to use a collection type for this, e.g.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE OR REPLACE TYPE varchar2_table AS TABLE OF VARCHAR2 (4000);
2 /
Type created.
SQL> SELECT empno, column_value
2 FROM emp, TABLE (varchar2_table (ename, job));
EMPNO COLUMN_VALUE
7369 SMITH
7369 CLERK
7499 ALLEN
7499 SALESMAN
7521 WARD
7521 SALESMAN
7566 JONES
7566 MANAGER
7654 MARTIN
7654 SALESMAN
7698 BLAKE
(snipped)
28 rows selected.
SQL> -
Get multiple values into one field
I want to get following two rows into one record.
Thank you in advance!
ID Name Category
109 John C1
109 John D8
Result:
ID Name Category
109 John C1, D8hi, i used centinul suggestion to create this is query.
WITH tablet AS
(SELECT '109' AS ID, 'John' AS NAME, 'C1' AS CATEGORY
FROM DUAL
UNION ALL
SELECT '109' AS ID, 'John' AS NAME, 'D8' AS CATEGORY
FROM DUAL)
SELECT ID, NAME,
LTRIM
(MAX (SYS_CONNECT_BY_PATH (CATEGORY, ','))KEEP (DENSE_RANK LAST ORDER BY ID),
) AS CATEGORY
FROM (SELECT ID, NAME, CATEGORY,
ROW_NUMBER () OVER (PARTITION BY ID ORDER BY CATEGORY)
AS curr,
ROW_NUMBER () OVER (PARTITION BY ID ORDER BY CATEGORY)
- 1 AS prev
FROM tablet)
GROUP BY ID, NAME
CONNECT BY prev = PRIOR curr AND ID = PRIOR ID
START WITH curr = 1;or
WITH tablet AS
(SELECT '109' AS ID, 'John' AS NAME, 'C1' AS CATEGORY
FROM DUAL
UNION ALL
SELECT '109' AS ID, 'John' AS NAME, 'D8' AS CATEGORY
FROM DUAL)
SELECT ID, NAME, SUBSTR (SYS_CONNECT_BY_PATH (CATEGORY, ','),
2)CATEGORY
FROM (SELECT ID, NAME, CATEGORY, COUNT (*) OVER (PARTITION BY ID) cnt,
ROW_NUMBER () OVER (PARTITION BY ID ORDER BY CATEGORY) seq
FROM tablet)
WHERE seq = cnt
START WITH seq = 1
CONNECT BY PRIOR seq + 1 = seq AND PRIOR ID = ID;Edited by: DeepakDevarapalli on Nov 12, 2009 2:45 PM
Edited by: DeepakDevarapalli on Nov 12, 2009 2:46 PM
Maybe you are looking for
-
How do I get my games to launch?
All of my games worked only about a week ago. Then I started getting the message "This game cannot be launched" on some of my games. What happened? I have plenty of room on my ipod and my computer. Hopefully it is something that can be easily take
-
Backup of application file system in oracle apps 11i
what are the ways to take the backup of application file system in oracle application 11i ? Can anyone suggest regarding this ? Application :11.5.10.2 OS : RHEL 3.0
-
We're deploying Lync voice in an office and we're going to deploy headsets that can connect to Lync Phones and the computer. So far I have tried two headsets and both of them create a dialtone as soon as you push the PC button. If you don't make a ca
-
CS3 stopped opening in Mountain Lion
Have indesign CS3 and it crashes before opening in my upgrade to Mountain Lion. How do you fix that?
-
Can't reinstall OSX - no destination volume
This morning, I was using my G4 Powerbook as usual. I shut it down to bring it to work. When I got there, powered up and got the question mark disk after a long, grey pause. Tried starting up holding option, and no startup disk is available. Then I t