How to convert column to row in 10g and calculate the count
876602 wrote:
Hi ,
i need to convert the column to row in my DB 10g , i cant use the Decode method because i have about 2000 items in MDN column
this is sample of my date ,
MDN Date
5C4CA98EABA3 20111205235240
5C4CA98EABA3 20110925121833
5C4CA98EABB0 20111025103700
5C4CA98EABB0 20111124103700
5C4CA98EABB5 20111030175717
5C4CA98EABB8 20110925142653
5C4CA98EABB8 20111126175853i need the result to be ,
MDN Date count
5C4CA98EABA3 20111205235240 ; 20110925121833 2
5C4CA98EABB0 20111025103700 ; 20111124103700 2
5C4CA98EABB5 20111030175717 1
5C4CA98EABB8 20110925142653 ; 20111126175853 2any help please ,
Edited by: 876602 on 15/12/2011 01:33 ص
SQL> with t as
2 (
3 select '5C4CA98EABA3' MDN ,'20111205235240' Dte from dual
4 union all
5 select '5C4CA98EABA3','20110925121833' from dual
6 union all
7 select '5C4CA98EABB0','20111025103700' from dual
8 union all
9 select '5C4CA98EABB0','20111124103700' from dual
10 union all
11 select '5C4CA98EABB5','20111030175717' from dual
12 union all
13 select '5C4CA98EABB8','20110925142653' from dual
14 union all
15 select '5C4CA98EABB8','20111126175853' from dual
16 )
17 select mdn,ltrim(sys_connect_by_path(dte,';'),';') s,rw as "count"
18 from
19 (
20 select mdn,dte,row_number() over(partition by mdn order by mdn) rw
21 from t
22 )
23 where connect_by_isleaf = 1
24 start with rw = 1
25 connect by prior rw = rw-1
26 and prior mdn = mdn
27 ;
MDN S count
5C4CA98EABA3 20111205235240;20110925121833 2
5C4CA98EABB0 20111025103700;20111124103700 2
5C4CA98EABB5 20111030175717 1
5C4CA98EABB8 20110925142653;20111126175853 2
Similar Messages
-
How to convert column to row in 10g
Hi ,
i need to convert the column to row in my DB 10g , i cant use the Decode method because i have about 2000 items in MDN column
this is sample of my date ,
MDN Date
5C4CA98EABA3 20111205235240
5C4CA98EABA3 20110925121833
5C4CA98EABB0 20111025103700
5C4CA98EABB0 20111124103700
5C4CA98EABB5 20111030175717
5C4CA98EABB8 20110925142653
5C4CA98EABB8 20111126175853i need the result to be ,
MDN Date
5C4CA98EABA3 20111205235240 ; 20110925121833
5C4CA98EABB0 20111025103700 ; 20111124103700
5C4CA98EABB5 20111030175717
5C4CA98EABB8 20110925142653 ; 20111126175853any help please ,
Edited by: 876602 on 15/12/2011 01:33 صNote the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*", so only for issues with the SQL Developer tool. Please post these questions under the dedicated {forum:id=75} forum.
Regards,
K. -
How to convert columns into rows using transpose function
Hi
anybody tell me how to convert columns values into rows using transpose function.Since BluShadow went to all the trouble to put it together, someone should use it.
See the post titled How do I convert rows to columns? here SQL and PL/SQL FAQ
John -
How to convert columns to rows
I have 70 columns and I need to convert them into rows. Please help!
Currently, it is showing as listed below
message 1 message 2 message 3 message 4 message 5 .......... message 70
system 1 20 10 40 60 100
system 2 40 30 50 80 110
system 3 60 60 70 90 120
The desire output
system 1 system 2 system 3
message 1 20 40 60
message 2 10 30 60
message 3 40 50 70
message 70Something like...
SQL> ed
Wrote file afiedt.buf
1 select decode(rn,1,'Empno :'||empno
2 ,2,'Ename ('||empno||') :'||ename
3 ,3,'Job ('||empno||') :'||job
4 ) as col
5 from emp
6 cross join (select rownum rn from dual connect by rownum <= 3)
7* order by empno, rn
SQL> /
COL
Empno :7369
Ename (7369) :SMITH
Job (7369) :CLERK
Empno :7499
Ename (7499) :ALLEN
Job (7499) :SALESMAN
Empno :7521
Ename (7521) :WARD
Job (7521) :SALESMAN
Empno :7566
Ename (7566) :JONES
Job (7566) :MANAGER
Empno :7654
Ename (7654) :MARTIN
Job (7654) :SALESMAN
Empno :7698
Ename (7698) :BLAKE
Job (7698) :MANAGER
Empno :7782
Ename (7782) :CLARK
Job (7782) :MANAGER
Empno :7788
Ename (7788) :SCOTT
Job (7788) :ANALYST
Empno :7839
Ename (7839) :KING
Job (7839) :PRESIDENT
Empno :7844
Ename (7844) :TURNER
Job (7844) :SALESMAN
Empno :7876
Ename (7876) :ADAMS
Job (7876) :CLERK
Empno :7900
Ename (7900) :JAMES
Job (7900) :CLERK
Empno :7902
Ename (7902) :FORD
Job (7902) :ANALYST
Empno :7934
Ename (7934) :MILLER
Job (7934) :CLERK
42 rows selected. -
How to convert Smart Form into PDF format and return the result in BAPI?
I want to convert a Smart Form into PDF format and return the result in BAPI.
can anyone tell me how it can be done with related example
regards
pranayhi,
smart form to pdf--
All you have to do is call your SF to get OTF and then concert it to PDF. Works like charm:
DATA: p_output_options TYPE ssfcompop,
p_control_parameters TYPE ssfctrlop.
p_control_parameters-no_dialog = 'X'.
p_control_parameters-getotf = 'X'.
CALL FUNCTION v_func_name "call your smartform
EXPORTING
output_options = p_output_options
control_parameters = p_control_parameters
IMPORTING
job_output_info = s_job_output_info.
call function 'CONVERT_OTF_2_PDF'
tables
otf = s_job_output_info-otfdata
lines = t_pdf
and if u need more u can check below links also
Check the below links..
Re: Smartforms to PDF
Re: smartform (otf) as pdf and sending as email-attachment
VISIT THIS LINK
Re: Smartforms to PDF
PLZ REWARD POINTS IF IT HELPS YOU
rgds
anver -
How to convert columns into rows
present result
Mat_num comp_code disc amount
800000 SG01 SAPLF005 0.00
800000 SG01 SAPLF005 31,500.00
6300001 SPM SAPLF005 0.00
6300001 SPM SAPLF005 108,888.00
APS100 SMTP SAPLF005 0.00
APS100 SMTP SAPLF005 0.00
required format
Mat_num disc SG01 SMTP SPM
800000 SAPLF005 31,500.00 0.00 0.00
800000 SAPLF005 0.00 0.00 0.00
6300001 SAPLF005 0.00 0.00 108,888.00
6300001 SAPLF005 0.00 0.00 0.00
APS100 SAPLF005 0.00 0.00 0.00
APS100 SAPLF005 0.00 0.00 0.00
Plain Text Attachment [ Scan and Save to Computer ]
REPORT Z_CALC2 .
TABLES : KNC1.
TYPE-POOLS: SLIS.
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
DATA: BEGIN OF ITAB OCCURS 0,
KUNNR LIKE KNC1-KUNNR,
BUKRS LIKE KNC1-BUKRS,
GJAHR LIKE KNC1-GJAHR,
USNAM LIKE KNC1-USNAM,
UMSAV LIKE KNC1-UMSAV,
END OF ITAB.
*Result table
TYPES BEGIN OF RES_ITAB.
* RES_ITAB(10) TYPE C DEFAULE 'ZRES_ITAB'.
INCLUDE STRUCTURE ZRES_ITAB.
TYPES END OF RES_ITAB.
SELECT-OPTIONS : CCODE FOR KNC1-BUKRS DEFAULT 'SG01' TO 'SPM '.
DATA : BEGIN OF COMP_ITAB OCCURS 0,
BUKRS LIKE KNC1-BUKRS,
END OF COMP_ITAB.
DATA: COLS TYPE I,
gap(10) TYPE c,
Company_title type string .
start-of-selection.
perform get_NUM_COLS.
perform get_structure.
perform create_dynamic_itab.
perform get_data.
* perform write_out.
FORM GET_NUM_COLS.
SELECT KUNNR BUKRS GJAHR USNAM UMSAV INTO TABLE ITAB FROM KNC1 WHERE
BUKRS IN CCODE.
CLEAR ITAB.
*CLEAR RES_ITAB.
LOOP AT ITAB .
COMP_ITAB-BUKRS = ITAB-BUKRS.
APPEND COMP_ITAB.
CLEAR COMP_ITAB.
ENDLOOP.
SORT COMP_ITAB BY BUKRS.
DELETE ADJACENT DUPLICATES FROM COMP_ITAB.
DESCRIBE TABLE COMP_ITAB LINES COLS.
ENDFORM.
*Get table structure
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
data fld_pos type i value 1.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( 'ZRES_ITAB' ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
XFC-COL_POS = fld_pos.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
fld_pos = fld_pos + 1.
endloop.
DO COLS TIMES.
clear xfc.
READ TABLE COMP_ITAB INDEX SY-INDEX.
XFC-COL_POS = fld_pos.
xfc-fieldname = COMP_ITAB-BUKRS .
xfc-datatype = 'F'.
* xfc-inttype = 'F'. 'details-type_kind.
xfc-intlen = 14.
* xfc-decimals = xdetails-decimals.
append xfc to ifc.
fld_pos = fld_pos + 1.
ENDDO.
clear xfc.
XFC-COL_POS = fld_pos.
xfc-fieldname = 'RECORD_TOTAL' .
xfc-datatype = 'F'.
xfc-inttype = 'F'.
xfc-intlen = 14.
* xfc-decimals = xdetails-decimals.
append xfc to ifc.
endform.
form create_dynamic_itab.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
LOOP AT ITAB.
<DYN_WA>-KUNNR = ITAB-KUNNR.
<DYN_WA>-USNAM = ITAB-USNAM.
DO COLS TIMES.
IF <DYN_WA>
DESCRIBE TABLE <dyn_table>.
*WRITE:/ SY-TFILL.
* Select Data from table.
* <dyn_table> = ITAB[].
*LOOP AT ITAB.
* RES-KUNNR = ITAB-KUNNR.
* RES-USNAM = ITAB-USNAM.
* CASE ITAB-GJAHR.
* WHEN 2005.
* RES-UMSAV1 = ITAB-UMSAV.
* WHEN 2006.
* RES-UMSAV2 = ITAB-UMSAV.
* WHEN 2007.
* RES-UMSAV3 = ITAB-UMSAV.
* ENDCASE.
* RES-TOTAL = RES-UMSAV1 + RES-UMSAV2 + RES-UMSAV3 .
* APPEND RES.
*ENDLOOP.
endform.
form write_out.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
endform.
Edited by: Alvaro Tejada Galindo on Feb 28, 2008 11:56 AMsolved myself
-
Hi,
I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data:
Time Stamp Power Output
11:00:00 AM 3kW
11:00:02 AM 2.9kW
11:00:04 AM 3.2kW
11:00:06 AM 3.1kW
The above data doesn't make any sense, but it is just for the purpose of this question.
So, I have to read 11:00:00 AM and 3kW initially - 3kW is the initial request that is sent. Then I have toRepeated forum post
Please view http://forums.ni.com/ni/board/message?board.id=170&message.id=294435
Regards,
Juan Galindo
Applications Engineer
National Instruments -
Convert columns to row equivalent to stragg function in oracle sql
Hi,
Sorry i forgot my Oracle version :
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - ProductionI searched in google but i didn't found the solution.
I looking for a function in discoverer equivalent to stragg sql function.
Note : stragg function convert columns to rows.
Thanks
SELECT deptno, stragg ('-' || ename)
FROM emp_test
GROUP BY deptno;
DEPTNO STRAGG_STR
10 -CLARK-KING-MILLER
20 -SMITH-FORD-ADAMS-SCOTT-JONES
30 -ALLEN-BLAKE-MARTIN-TURNER-JAMES-WARD
3 rows selected.Edited by: Salim Chelabi on 2010-01-29 08:32Hi again,
*1- I created my function in my schema.*
CREATE OR REPLACE TYPE t_string_agg AS OBJECT
g_string VARCHAR2(32767),
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER
SHOW ERRORS
CREATE OR REPLACE TYPE BODY t_string_agg IS
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER IS
BEGIN
sctx := t_string_agg(NULL);
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER IS
BEGIN
SELF.g_string := self.g_string || ',' || value;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER IS
BEGIN
returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER IS
BEGIN
SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
RETURN ODCIConst.Success;
END;
END;
SHOW ERRORS
CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;
SHOW ERRORS
*2- I ran my query in my schema with sqlplus.*
SELECT deptno,ename,sal, string_agg(ename)over(partition by deptno) AS employees
FROM emp_test
order by deptno;
DEPTNO ENAME SAL EMPLOYEES
10 CLARK 2450 CLARK,KING,MILLER
10 KING 5000 CLARK,KING,MILLER
10 MILLER 1300 CLARK,KING,MILLER
20 JONES 2975 JONES,FORD,ADAMS,SMITH,SCOTT
20 FORD 3000 JONES,FORD,ADAMS,SMITH,SCOTT
20 ADAMS 1100 JONES,FORD,ADAMS,SMITH,SCOTT
20 SMITH 800 JONES,FORD,ADAMS,SMITH,SCOTT
20 SCOTT 3000 JONES,FORD,ADAMS,SMITH,SCOTT
30 WARD 1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 TURNER 1500 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 ALLEN 1600 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 JAMES 950 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 BLAKE 2850 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 MARTIN 1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
14 rows selected.
*3- I import this function in discoverer administration*
4- My problem :When i use the function string_agg(ename)over(partition by deptno) in discover deskto i got the error you can't use over in this place.
Any ideas.
Thank in advance.
Regards Salim. -
Need help with query for converting columns to rows
Hello,
I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
I have a table which is having multiple columns as follows:
Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
Col1 Col2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
I 0Please anybody help me in writing the query for this..Is this what you are expecting:
SQL> WITH T AS
2 (
3 SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
4 )
5 SELECT 'X' col1, X col2 FROM T
6 UNION ALL
7 SELECT 'Y' col1, Y col2 FROM T
8 UNION ALL
9 SELECT 'Z' col1, Z col2 FROM T
10 UNION ALL
11 SELECT 'A' col1, A col2 FROM T
12 UNION ALL
13 SELECT 'B' col1, B col2 FROM T
14 UNION ALL
15 SELECT 'C' col1, C col2 FROM T
16 UNION ALL
17 SELECT 'D' col1, D col2 FROM T
18 UNION ALL
19 SELECT 'E' col1, E col2 FROM T
20 UNION ALL
21 SELECT 'F' col1, F col2 FROM T
22 UNION ALL
23 SELECT 'G' col1, G col2 FROM T
24 UNION ALL
25 SELECT 'H' col1, H col2 FROM T
26 UNION ALL
27 SELECT 'I' col1, I col2 FROM T
28 /
C COL2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
C COL2
I 0
12 rows selected. -
Hi All,
I need help in building view which actually can show columns data as row.
e.g.
row is as follows
Name Age Salary
ABC 25 10000
BBC 28 12000
The above tables data I want to get as
Name ABC BBC
Age 25 28
Salary 10000 12000
Thanks in advance.Even if I don't really understand such requirement, I wrote some times ago such function to play around that :
Re: Converting Columns into rows
Nicolas. -
Hi. Does anyone know how to turn columns into rows ie:
select field1, field2, field3, field4, field5 from table
desired result:
field1 field2
field1 field3
field1 field4
field1 field5
Thank you!Something like this ?
select field1
, case n.l
when 1 then field2
when 2 then field3
when 3 then field4
when 4 then field5
end field
from table
, (select level l from dual connect by level <= 4) n -
Hi Experts,
How to Place Approve and Reject Button in every row to approve and reject the particular order in sapui5.
Please Kindly help me.
Thanks & Regards
Chitti BabuHi Chitti,
You can achieve this using sap.m.CustomListItem.
View :
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns:l="sap.ui.layout" xmlns="sap.m" controllerName="demoallinonegrid.tablewithscroll"
xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Title">
<content>
<ScrollContainer horizontal="true" width="100%">
<Table id="empTable">
<headerToolbar>
<Toolbar>
<Label text="Employees"></Label>
</Toolbar>
</headerToolbar>
<columns>
<Column width="12em">
<Label text="Employee Id"></Label>
</Column>
<Column width="12em">
<Label text="Last Name"></Label>
</Column>
<Column width="12em">
<Label text="First Name"></Label>
</Column>
<Column width="12em">
<Label text="Title"></Label>
</Column>
<Column width="12em">
<Label text="Approve"></Label>
</Column>
<Column width="12em">
<Label text="Reject"></Label>
</Column>
</columns>
</Table>
</ScrollContainer>
</content>
</Page>
</core:View>
Controller:
var model = new sap.ui.model.json.JSONModel();
model.loadData("http://services.odata.org/Northwind/Northwind.svc/Employees?$format=json",null,false,'GET',false,null);
this.getView().byId("productTable").setModel(model);
var template = new sap.m.ColumnListItem({
cells:[
new sap.m.Text({text:"{EmployeeID}"}),
new sap.m.Text({text:"{LastName}"}),
new sap.m.Text({text:"{FirstName}"}),
new sap.m.Text({text:"{Title}"}),
new sap.m.Button({text:"Approve"}),
new sap.m.Button({text:"Reject"})
this.getView().byId("empTable").bindAggregation("items","/value",template);
Output:
Regards,
KK -
How to get column names for a specific view in the scheme?
how to get column names for a specific view in the scheme?
TIA
Don't have DD on the wall anymore....or this?
SQL> select text from ALL_VIEWS
2 where VIEW_NAME
3 ='EMP_VIEW';
TEXT
SELECT empno,ename FROM EMP
WHERE empno=10 -
How to convert non-fillable forms in words and PDF into fillable forms?
Hai,
How to convert non-fillable forms in words and PDF into fillable forms?Hi Mahalcs
Please See the below link for reference : http://www.adobe.com/in/products/acrobat/convert-existing-forms-to-fillable-pdfs.html
Also See , http://www.adobe.com/content/dam/Adobe/en/products/acrobat/pdfs/adobe-acrobat-xi-convert-f orms-into-fillable-pdf-tutorial_ue.pdf -
How to save column widths in tag monitor and tag config editor?
how to save column widths in tag monitor and tag config editor?
The attached example may help.
After launching the editor, I locate a reference to the front panel control named "Tag List".
This is type cast as a multicolumn list box which then allows me to increment through all of the cells and set the widths as i go.
Trying to help,
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction
Attachments:
Set_Width2.vi 60 KB
SET_WIDTH.JPG 94 KB
Maybe you are looking for
-
I wont to hide a elected column in JTable. how it to do
-
MAIL V6.6 in Mavericks?
I am seriously hating Mail V7.1, as I've posted elsewhere, I am still unable to view html images in my email. I have tried clicking "load html images" in Prefs On & Off, no diff. I have re-installed the OS X 10.9.1 combined update. I could try rebuil
-
Is there any way to recover my iphoto library if I "securely emptied" my trash with it in there?
-
IMAP - can't save drafts, can't see sent messages
Hi I set up two email accounts as IMAP when we moved to a new server - they used to be POP3 accounts. Now I can't save any emails from either of those addresses and there's no record of sent mails either. I've been to both sent and draft mailboxes an
-
My scratch disks previews folders select as "Same as Project" even though I selected another folder and saved before. Old and new projects. Help.