Merge Multiple Rows in to a single Row.
Hi
Tab_A
Col_1
Col_2
Col_3
I want resultant rows to merge on base of Col_1 (i.e. single - delimited merge row for distinct value of Col_1)
Example
Table_A
Col_1 | Col_2 | Col_3
A | 1 | 23
A | 2 | 25
B | 3 | 5
B | 6 | 9
C | 7 | 8
Required Result
Col_1 | Col_2 | Col_3
A | 1-2 | 23-25
B | 3-6 | 5-9
C | 7 | 8
Wishes
Jawad
You can try with sys_connect_by_path, but I've found Re: Aggregate function to bring values in list form more performant.
You can write your query like this:
SELECT col_1
, concat_all(concat_expr(col_2,'-')) col_2
, concat_all(concat_expr(col_3,'-')) col_3
FROM yourtableMHE
Similar Messages
-
Merging multiple rows in to a single row (when rows meet merging criteria)
Hi
I have a scenario to merge multiple rows in to a single rows when the data in those rows fall in merge criteria .Below is how my data is
Now the merging logic for the above rows is , we need to combine multiple rows in to a single row when the data in those rows permits us to do in that way. Simply saying , its like sandwich where we combine multiple things to a single piece.The output for
the above rows should be
Here we combined Row 1 ,2, 3 in to a single row as the data in those rows permits to merge in to single row. But the row 4 cannot be combined to any of those rows because the data in those rows doesn't permits us do a merge ( As the value of the column
JobSource for the row 4 is different from the other rows ) .
My original data has 56 columns , but for readability i kept only 9 columns.
can you please throw some idea on how to achieve this scenario. I know we need to use CTE for achieving this, but i am not able succeed in doing an iteration on multiple rows.
Appreciate your response .Thanks for your reply .
Rule for merging is simple . First of all there is no unique row identifier for each row , the fact table is not having an identity column in the database . I called row 1 , row 2 etc in my post above only to make better explanation of my scenario.
The rule for merge is below.
1) we can combine only when the data in a column for one row is null & the data in same column for the other row is not null . It should also satisfy the condition where the data in other columns should conflict each other.
2) Data for all columns for the merging rows should not be conflicting (i.e. we should not merge the rows when the data in a column is not equal to the same column in the other row
,considering not null value)
Steps in merging the above source data :
1) Consider the case of row 1 and row 2 in the source, we can combine these rows as the data is satisfying the rule 1 for columns (Jobsource,Flight, Package,Update,Iscancelled
,Result, Severity) and columns (JobID and RuleName ) fall under rule 2. we merge these two rows in to a single row and keep in that in the table.
2) Then the resulting row is again merged with the second row which is present above by applying the rule 1 and rule 2 . Below would be output of merge operation.
Now there would be only two rows in the output . But these rows cannot be merged as the data doesn't satisfy the merge rules 2 . As Jobsource for the row 1 in the above output is "PresubmissionSource" which is not equal
to "PostSubmission" jobSource which is in row 2. So these two rows are left unmerged .So the above two rows would be the output of merge operation on my source data.
This process has to be repeated for all the rows in the table. As of now my table as 92 Million rows with 56 columns which need to be considered for merging rows. I replicated my scenario in 9 columns and 4 rows to understand better. -
PL/SQL muliple row insert for a single row
I need to insert multiple rows based on a single row record. Below are the table structures and sample data
CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
CREATE TABLE TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20))
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('hello','asd','fgh','ert',null);For the above record in table TEST_SAMPLE, three records have to be populated\inserted into table TRANSACTION. In PL/SQL
stored procedure i am inserting records to TRANSACTION when ATTR_1 or ATTR_2 or ATTR_3 or ATTR_4 is not null.
Please help me to find a better way for the above insert to table TRANSACTION?Thanks for helping me here. For the sample record in table TEST_SAMPLE i mentioned above three records need to be inserted in table TRANSACTION. you have this, or?
CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
CREATE TABLE TEST_TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20));
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 1','asd','fgh','ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 2',null,'fgh','ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 3','asd',null,'ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 4','asd','fgh',null,null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 5','asd',null,null,null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 6',null,null,null,null);
commit;
insert into TEST_TRANSACTION
select NAME,
ATTR_1
from TEST_SAMPLE
where ATTR_1 is not null
union all
select NAME,
ATTR_2
from TEST_SAMPLE
where ATTR_2 is not null
union all
select NAME,
ATTR_3
from TEST_SAMPLE
where ATTR_3 is not null
union all
select NAME,
ATTR_4
from TEST_SAMPLE
where ATTR_4 is not null
commit;
select *
from TEST_TRANSACTION
order by 1;
Table created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Commit complete.
10 rows created.
Commit complete.
NAME ATTR
record 1 asd
record 1 fgh
record 1 ert
record 2 fgh
record 2 ert
record 3 ert
record 3 asd
record 4 fgh
record 4 asd
record 5 asd
10 rows selected. -
Merge two rows & show in a single row in table results
Hi, I need to merge 2 rows having 3 columns in a single row in table view
The cols are currently shown as :
Project NO-------(Current_Month) Revenue----------(Prior_Month) Revenue
123123 10000
20000
Revenue is a single column with revenue for diffreent Period.
10000 is for May
20000 is for April
Project NO for both are same, just the periods are different. if I am not displaying Period i need to merge the 2 rows & show as
Project NO-------(Current_Month) Revenue----------(Prior_Month) Revenue
123123 10000 20000
Please let me know how we can acheive this??
thanx
Pankaj123123 is the project number..
the above is not getting displayed properly....as the blank spaces are removed...
Please consider this -
Multiple pages that edit a single row
I have searched on tabs and editing a single row using multiple pages and I am confused. I don't want to use java as I am trying to not learn that too...
What I am trying to do sounds like it has been explained before but let me do this again...
I have a record that is too large to fit on a single screen. This makes for a cumbersome entry process. The record is actually broken into four "logical" chunks. Main, Sub1, Sub2 and Sub3.
I have made a list that will allow the record to be selected and call the first logical page... L1.
I have made tabs that show all the pages and allow me to navigate between them quickly.
When I get to L1 all the data is there. I may not change any data on that page and go directly to L2 through L4. However the record is not brought forward onto those pages. So the pages are not related (and I don't have the terminology right I know :) and I could "link" the pages. So here is what I would like the application to do;
1. Display a list and allow the user to select the record to edit.
2. Upon edit go to the first page (tab).. this works
3. Allow the user to select a tab and the page displays the data for the record selected
4. Allow the user to complete the edits and save the record. Upon save the user is returned to the list in step 1.
I was thinking there are several ways to do it... but I was hoping someone could save me a bunch of trial and error (emphasis on the error) ...
1. When navigating off the page save the record, pass the key and re-read the record... ugly huh?
2. Pass all the session data for the record over to the next screen. Is that possible? e.g pxx_field1 = pyy_field1
The the question was does a template with two level tabs keep the record data between tabs?
Any help is greatly appreciated.
SamI think this works... kinda
1. I have a "list" that allows the selection of the item to edit.
2. That list opens a page that is the "header" page for a tab set.
3. Each page in the tab set uses the same "ID" to read the record and display the columns. That is how it would work if the list called each individual page.
4. I modified the "slave" tabs to have the "ID" of the "header" page.
This displays the correct data on each page. And it looks like the "apply changes" button saves the changes on the page.
Caveats inlclude (I think as I haven't done exhaustive testing"
1. "apply changes" must be done at each page where there were changes or they would be lost.
2. The first dispaly of the page is blank. Clicking on the tab a second time displays the data. This is true if it is the first time a user selects a record in a session (the "slave" tabs are blank) or if it is a subsequent record update (the "slave" tabs have the last records data.
Thoughts... is this really boring to everyone but me?
Sam -
To make Three row values in a single row
Hi,
Below is the Table Format i have.
Here for the first Mail_ID i have 3 mail addresses.similarly for second ID too.
I want First three rows to be in a single row.and so on...
Plz help in doing this.
Thanks
DeepaDeepa,
Check if this helps.. Does dynamic conersion of data to columns ..
--Your Email table
create table #temp (mailid int,to_mail varchar(100))
insert #temp select 1,'[email protected]'
insert #temp select 1,'[email protected]'
insert #temp select 1,'[email protected]'
insert #temp select 2,'[email protected]'
insert #temp select 2,'[email protected]'
insert #temp select 3,'[email protected]'
--Constructing a temp table to hold data with row_numbers
select *,row_number() over(partition by mailid order by to_mail) as rn
into #t
from #temp
--declaration of variables
declare @n int,@list varchar(max),@sql nvarchar(max)
set @n=(select max(rn) from #t)
--Population of list to form the dynamic query
;with cte
as
select cast(',[email1]' as varchar(max)) as ch,1 as num
UNION ALL
select cast(ch+',[email'+cast((num+1) as varchar(100))+']' as varchar(max)) as ch,num+1 as num
from cte where num<@n
select top 1 @list=stuff(ch,1,1,'')
from cte
order by num desc
--Formulating the complete dynamic query
set @sql='
select mailid,'+@list+'
from
select mailid,to_mail,''email''+cast(rn as varchar) as emailnum from #t
) tab
PIVOT
max(to_mail) for emailnum in ('+@list+')
) pvt'
exec sp_executesql @sql
--clean up
drop table #t
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Hi All
I have facing the Single row sub query Error . I tried to resolve , but my condition not working .can please any help to rewrite the query (sub query)
SELECT DISTINCT wdlsv.serial_number
,wdlsv.date_shipped
,wdlsv.inventory_item_id
,wdlsv.organization_id
,wdlsv.lot_number
,(select distinct engine from xxtc_tr_pr_open_data where chassis=wdlsv.serial_number and rownum=1
union
select distinct replace(replace(attribute11,'*',''),' ','')
from xxtc_chassis_scanout_details
where serial_number=wdlsv.serial_number
and operation_line_code ='CHASSIS') "ENGINE_NO"
,oola.attribute1 oh_excise_no
,msi.attribute16 vehicle_type
,bbom.attribute2 model_no
,xxst.tariff_code tariff_code
,substr(xxst.color_type,1,1) color_type
,(SELECT TO_CHAR(trunc(rt.transaction_date),'RRRRMMDD')
FROM rcv_transactions rt,
rcv_shipment_lines rsl,
rcv_shipment_headers rsh
WHERE rsh.shipment_header_id=rsl.shipment_header_id
AND rt.shipment_header_id=rsl.shipment_header_id
AND rsl.attribute1=wdlsv.lot_number
AND rt.organization_id=wdlsv.organization_id
AND rt.organization_id=rsh.organization_id
AND ROWNUM<=1
union
select distinct to_char(xxtp.indent_import_date,'RRRRMMDD')
from xxtc_tr_pr_open_data xxtp
where xxtp.chassis = wdlsv.serial_number) "CKD_IMPORT_DATE_YEAR"
,to_char(xxtp.indent_import_date,'RRRRMMDD') import_date
FROM WSH_DELIVERY_LINE_STATUS_V WDLSV
,oe_order_headers_all ooha
,oe_order_lines_all oola
,mtl_system_items_b msi
,bom_bill_of_materials bbom
,xxtc_sales_tax_cal xxst
WHERE 1=1
AND PICK_STATUS = 'C'
AND delivery_status = 'CL'
AND ooha.header_id = wdlsv.source_header_id
AND ooha.header_id = oola.header_id
AND oola.line_id = wdlsv.source_line_id
AND msi.inventory_item_id = wdlsv.inventory_item_id
AND msi.organization_id = wdlsv.organization_id
AND bbom.assembly_item_id = wdlsv.inventory_item_id
AND bbom.organization_id = wdlsv.organization_id
AND xxst.inventory_item_id = wdlsv.inventory_item_id
AND xxst.organization_id = wdlsv.organization_id
and upper(msi.attribute15) not like 'SUB%'
AND WDLSV.SERIAL_NUMBER IS NOT NULL;
Regards
SanjayThis forum is for questions about working with SQL*Developer. The title is "SQL Developer (Not for general SQL/PLSQL questions)" and yours is a general SQL question. You should get a better answer by re-posting in the SQL and PL/SQL forum in the Oracle Database section. Please mark this tread as answered and re-post there.
-
Merging corresponding coloumns of multiple rows to get a single row
hi,
plz help me in sorting out this problem.this is my query.
select distinct h.ccid,
DECODE(a.prmcd,'ELEREP', sum(d.period_net_dr - d.period_net_cr)) A,
DECODE(a.prmcd,'GENREP', sum(d.period_net_dr - d.period_net_cr)) B
DECODE(a.prmcd,'BLDGREP', sum(d.period_net_dr - d.period_net_cr)) C,
DECODE(a.prmcd,'MCREP', sum(d.period_net_dr - d.period_net_cr)) D,
DECODE(a.prmcd,'SPARES', sum(d.period_net_dr - d.period_net_cr)) E
from fics_prmtrval a,
figl_code_combinations_mview_1 c,
figl_balances_mview_1 d,
fims_comstr e,
FIMS_PCSCMSTR f,
FIMS_CCMSTR g,
FIMS_CODECOMBINATIONS h
where a.prmcd in('ELEREP', 'GENREP', 'MCREP', 'BLDGREP', 'SPARES')
and a.prmval = c.segment4
and c.code_combination_id = d.code_combination_id
and e.cocd = c.segment1
and f.PCSCCD = C.SeGMENT2
and g.CCCD = C.SEGMENT3
and h.COID = e.coid
and h.PCID = f.PCSCID
and h.CCID = g.CCID
and h.stid = 1
and h.coid = 1
and h.pcid = 1
group by h.ccid,
g.ccnm,
a.prmcd
the output of this is :
CCID A B C D E
16 1
16 2
17 3
17 4
17 5
17 6
but i need the out put in the following format:
CCID A B C D E
16 1 2
17 3 4 5 6
plz suggest me a possible solution for thisHi,
Enclose all your decodes by MAX like this MAX( DECODE(...)) and group your result by ccid column only and remove the distinct key word( it is not needed since you will be already grouping on ccid so distinct would be kind of redundant ).
For any furthur clarifications refer this link, it is easy to follow.
http://asktom.oracle.com/pls/ask/f?p=4950:8:8495196364001188355::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:124812348063
Thanks,
Khalid -
SQL Multiple Columns Displayed in a Single Row
Hello everyone,
I have 2 tables, Product and Product_Name, one Product can have more than one name.
I need to retrieve it in such a way that I show the Product_ID followed by all the names this product has.
I'm not able to make it, every way I try I get the Product ID duplicated and several rows with a different product name on each row as follows:
1, 'Iron Z"
1, 'Iron M'
1, 'Iron N'
2, 'Wood P'
2, 'Wood M'
What I need is:
1, Iron Z, Iron M, Iron N
2, Wood P, Wood M
Thanks and Regards.Hi,
user10103934 wrote:
Thank you for the answer Frank,
Iron Z, Iron M and Iron N would be 3 different entries on the same column.
I'm sure the LISTAGG function would resolve this, the problem is that I was hoping to get a solution on pure SQL or PL/SQL, maybe with a nested Select.
My Oracle version is 10g Express Edition.LISTAGG is pure SQL, but it was only introduced in Oracle 11.2. Everything mentioned below should work in Oracle 10.
The STRAGG function from that page is very useful. You have to copy and install about 60 line of PL/SQL code. Do that once, and then you can use it hundreds of times in hundreds of queries, just as if it was a built-in function. The main problem with STRAGG is that it's hard to get soprted output from it. There's a modified version, designed for sorted output, on this thread:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15637744429336
Never used it. Can't vouch for it.
SYS_CONNECT_BY_PATH seems to be the most popular way of doing string aggregation in Oracle 10. The example given on the Oracle Base page (which I posted in my last message) is a little clumsy and inefficient. See the following thread for a better example, using CONNECT_BY_ISLEAF:
Re: Concatenate strings from more rows into one row.
or, now that I see it, Pollywog's example above.
Edited by: Frank Kulash on Jun 11, 2010 2:24 PM -
Multiple row data in a single row
I have a table like the following:
AGREEMENT_ID SERVICE_CODE SERIAL_NO
22 CV CE095F0011007884F
22 HS 2509b000121373869
22 NG 2509B000121265554
22 SG 2509B00012120278D
22 SM PAFABM0716140704
22 SN G32X2MI808300348
22 SP CE095F00110045416
22 SV 2509B000121363230
22 SW CE095F00110037377
I would like to have it in the following format
Agreement_id CV HS NG SG SM SN SP SV SW --(These are the columns)
22 CE095F0011007884F 2509b000121373869 2509B000121265554 ....
(This is data)
Need to do it in a single Query....
Want an advice
Regards
Chaitanya.S.S.KHi,
SQL> l
1 with tbl as
2 (select 22 id, 'CV' service, 'CE095F0011007884F' serial from dual
3 union all
4 select 22, 'HS','2509b000121373869' serial from dual
5 union all
6 select 22, 'NG','2509B000121265554' serial from dual
7 union all
8 select 22, 'SG','2509B00012120278D' serial from dual
9 union all
10 select 22, 'SM','PAFABM0716140704' serial from dual
11 union all
12 select 22, 'SN','G32X2MI808300348' serial from dual
13 union all
14 select 22, 'SP','CE095F00110045416' serial from dual
15 union all
16 select 22, 'SV','2509B000121363230' serial from dual
17 union all
18 select 22, 'SW','CE095F00110037377' serial from dual
19 union all
20 select 23, 'SW','CE095F00110037377' serial from dual)
21 select id,
22 max(decode(service,'CV',serial)) "CV",
23 max(decode(service,'HS',serial)) "HS",
24 max(decode(service,'NG',serial)) "NG",
25 max(decode(service,'SG',serial)) "SG",
26 max(decode(service,'SM',serial)) "SM",
27 max(decode(service,'SN',serial)) "SN",
28 max(decode(service,'SP',serial)) "SP",
29 max(decode(service,'SV',serial)) "SV",
30 max(decode(service,'SW',serial)) "SW"
31 from tbl
32* group by id
SQL> /
ID CV HS NG SG SM SN SP SV SW
22 CE095F0011007884F 2509b000121373869 2509B000121265554 2509B00012120278D PAFABM0716140704 G32X2MI808300348 CE095F00110045416 2509B000121363230 CE095F00110037377
23 CE095F00110037377
SQL> HTH,
Nicolas. -
How to convert multiple string values in a single row from nvarchar to int
suppose I have a table like below.all these values are in nvarchar. How would I find the minimum year from START_DATE??
PRODUCT_CODE
PRODUCT_DESC
START_DATE
P00002933
VITAMINE C
2005,2000,2011,2001,2002
P00003087
BIOFENAC
2011,2009,2006,2007,2004,2005
P00000155
AMOXYPEN
2006,2007,2008,2009,0000,2001
P00002325
SAHHA FARINE
2008,2003,2002,2001,2009
P00005666
AMOXYPEN
2007,2008,2006,2009,0000,2001Create the split function:
CREATE FUNCTION Split (
@InputString VARCHAR(8000),
@Delimiter VARCHAR(50)
RETURNS @Items TABLE (
Item VARCHAR(8000)
AS
BEGIN
IF @Delimiter = ' '
BEGIN
SET @Delimiter = ','
SET @InputString = REPLACE(@InputString, ' ', @Delimiter)
END
IF (@Delimiter IS NULL OR @Delimiter = '')
SET @Delimiter = ','
--INSERT INTO @Items VALUES (@Delimiter) -- Diagnostic
--INSERT INTO @Items VALUES (@InputString) -- Diagnostic
DECLARE @Item VARCHAR(8000)
DECLARE @ItemList VARCHAR(8000)
DECLARE @DelimIndex INT
SET @ItemList = @InputString
SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
WHILE (@DelimIndex != 0)
BEGIN
SET @Item = SUBSTRING(@ItemList, 0, @DelimIndex)
INSERT INTO @Items VALUES (@Item)
-- Set @ItemList = @ItemList minus one less item
SET @ItemList = SUBSTRING(@ItemList, @DelimIndex+1, LEN(@ItemList)-@DelimIndex)
SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
END -- End WHILE
IF @Item IS NOT NULL -- At least one delimiter was encountered in @InputString
BEGIN
SET @Item = @ItemList
INSERT INTO @Items VALUES (@Item)
END
-- No delimiters were encountered in @InputString, so just return @InputString
ELSE INSERT INTO @Items VALUES (@InputString)
RETURN
END -- End Function
GO
Use the below script:
create table Table1 (Product_Code varchar(50),Product_Desc varchar(10),sStart_date varchar(MAX))
Insert into Table1 Values('P00002933','VITAMINE C','2005,2000,2011,2001,2002'),
('P00003087','BIOFENAC','2011,2009,2006,2007,2004,2005')
Select Product_Code,Product_Desc ,MIN(Item) Minstart_date
From Table1 A
Cross apply Split(A.sStart_date,',') B
Group by Product_Code,Product_Desc
Drop table Table1 -
Template:Multiple field result in a single row, comma separated
Hello,
without* having to write a function in Pl/SQL, is it possible, when I have this query,
select
"DOSSIER"."ID" as "DOSSIERID",
"DOSSIER"."TITLE" as "TITLE",
"DVD"."ID" as "DVDID",
"DVD"."NAME" as "DVDNAME",
"DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
"ELEMENTS"."ID" as "ELEMENTSID",
"ELEMENTS"."NAME" as "ELEMENTSNAME",
"ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
from "DOSSIER" "DOSSIER",
"DVD" "DVD",
"ELEMENTS" "ELEMENTS"
where "DVD"."ID_DOSSIER"="DOSSIER"."ID"
and "ELEMENTS"."ID_DVD"="DVD"."ID"
and "DOSSIER"."TITLE" = 'FIGARO'**Instead of having this result ( with break in the template)*
FIGARO C2008-203 12l10201.tif
12l10202.tif
12l11101.tif
12l11102.tif
12l11201.tif
12l11202.tif
12l12101.tif
12l12102.tif
C2008-204 12l12202.tif
12l13101.tif
12l13102.tif
12l13201.tif
12l13202.tif
12l14101.tif
12l14102.tif
12l14201.tif
12l14202.tif
12l15101.tif
12l15102.tif
12l15201.tif
C2008-205 12l15202.tif
12l16101.tif
12l16102.tif
12l16201.tif
12l16202.tif
12m01101.tif
12m01102.tifhaving this result, WITH the element only, comma separeted??? ( I can have from 0 to 500 elements)
FIGARO
DVD: C2008-203
Elements: 12l10201.tif, 12l10202.tif, 12l11101.tif, 12l11102.tif, 12l11201.tif, 2l11202.tif, 12l12101.tif, 12l12102.tifthanks, RoselineThis should help you http://tkyte.blogspot.com/2007/03/stringing-them-up.html
-
Combine multiple rows of table in single row
Hi Experts,
I have a table of below format.
MSDNID
WALL_BAL
WALL_DATE
123
34
06-Sep-13
123
56
07-Sep-13
123
78
08-Sep-13
123
65
09-Sep-13
123
34
10-Sep-13
123
87
11-Sep-13
Now I have to create a new table. which should contain unique MSDNID with WALL_BAL in different column .
Like below
MSDNID
DAY1_BAL
DAY2_BAL
DAY3_BAL
DAY4_BAL
DAY5_BAL
DAY6_BAL
123
87
34
65
78
56
34
How can I write a query for this?in 10g , you can use something like
select MSDNID,
max(decode(WALL_DATE, '11-Sep-13', WALL_BAL, null) day_1_bal,
max(decode(WALL_DATE, '06-Sep-13', WALL_BAL, null) day_6_bal
from t
group by MSDNID;
But it only works if you have limited # of days. -
Obiee report two rows data present in single row
Hi Experts,
I have facing one problem how to reslove this problem let me know.
In DB Table like this.
Sno **** Value1 **** Value2
10 ******** 100 ******* 0
10 **** *** 0 ******* 200
i want to out put Obiee reports like this ?????????
sno ***** value1 **** value2
10 ****** 100 **** 200
How to achive this please tell me any method
i am using obiee 10.1.3.4.1 version (i am try to create report OBIEE answers )
Thanks
Satya
Edited by: satya vardhan on Jul 11, 2011 6:56 PMTry going it by Sno.
If you are using Pivot Table, try changing measures from columns to rows and see. I vaguely remember doing this would address your need
Thanks,
Vinag -
Concatenation of row data into a single row
Hi,
I have table which has the data in the following way.
col1 col2 col3
a 1 one
a 2 two
a 3 three
b 1 dfdf
b 2 sfdhh
c 1 zgdhi want data in the following way.
col1 col2 col3
a 1,2,3 one,two,three
b 1,2 dfdf,sfdhh
c 1 zgdhCan any body help me.
Thanks in advancemay be this will work
WITH tab AS
(SELECT 'A' col1,1 col2, 'one' col3 FROM dual
UNION ALL
SELECT 'A' col1,2 col2, 'two' col3 FROM dual
UNION ALL
SELECT 'A' col1,3 col2, 'three' col3 FROM dual
union all
SELECT 'B' col1,1 col2, 'abc' col3 FROM dual
UNION ALL
SELECT 'B' col1,2 col2, 'defg' col3 FROM dual
UNION ALL
SELECT 'C' col1,1 col2, 'hijcol' FROM dual
union all
SELECT 'C' col1,2 col2,'klm' col3 FROM dual
SELECT col1
, ltrim(MAX(SYS_CONNECT_BY_PATH(col2,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS col2,
ltrim(MAX(SYS_CONNECT_BY_PATH(col3,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',')as col3
FROM ( SELECT col1
, col2,col3
, ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2) AS curr
, ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2) -1 AS prev
FROM tab )
GROUP BY col1
CONNECT BY prev = PRIOR curr AND col1 = PRIOR col1
START WITH curr = 1;
COL1 COL2 COL3
A 1,2,3 one,two,three
B 1,2 abc,defg
C 1,2 hijcol,klm
Maybe you are looking for
-
Hi, I bought an Ipod touch in Dubai. When I upated to iOs 6, everytime I would download an app it will says that it's not available in the emirates store and I should change to the US store. But before i updated to iOs 6 i have been successfuly down
-
Can I have two versions of the same original live in separate projects?
I am not an Aperature or photography expert. I scanned in a ton of old family photos with multiple snaphots on a page and in a single file. Then I imported into Aperature, created new versions, one for each snapshot, then cropped each snapshot, so ea
-
Problem in : File to IDoc
Hi, I am working on a file to IDoc scenario.The logical name for the sender system is maintained in the SLD.I am not populating the control record in the mapping. When am executing the scenario, the status message in SXMB_MONI is showing reques
-
I got my iPhone 4 just over a week ago and I had it for one day and then the new software came out so I was like awesome I will update it and I did on my iPhone and also on my iPod 4th gen but now I am having problems using FaceTime and iMessage. Whe
-
How to use boolean operator to get count
Hi All, In my query i need to add a field Count which shows number. Meaning, Column A ColumnB ColumnC Count 100 50 0 2 55 60 76 3 79 0 0