Merge rows
Hi everyone
Im using toad for oracle version 9.6.And preparing a script to count the number of employees available per division and per section.
Now i manage to convert the rows into columns and my output look as follows.
Division Number Of employees ICT Section IA section
CSD 45 45
CSD 10 10
However i want the results to be as this one below:
Division Number Of employees ICT Section IA section
CSD 55 45 10
You can hav a look on this coding , i used procedures since there is no specific table containing this data
select xxx.get_org_div(p.org_id,p.business_group_id) division,
count(a.employee_number) Number Of employees ,
decode(xxx.get_org_sec(p.org_id,p.business_group_id),'ICT',count(a.employee_number),null) ICT Section
decode(xxx.get_org_sec(p.org_id,p.business_group_id),'IA',count(a.employee_number),null) IA Section
from employees a,assignment p
where a.person_id = p.person_id
group by xxx.get_org_sec(p.org_id,p.business_group_id),
xxx.get_org_div(p.org_id,p.business_group_id)
and i have tried this one but it gives an error,'Not a single-group group function'
select xxx.get_org_div(p.org_id,p.business_group_id) division,
count(a.employee_number) Number Of employees ,
max(decode(xxx.get_org_sec(p.org_id,p.business_group_id),'ICT',count(a.employee_number),null) ICT Section
max(decode(xxx.get_org_sec(p.org_id,p.business_group_id),'IA',count(a.employee_number),null) IA Section
from employees a,assignment p
where a.person_id = p.person_id
group by xxx.get_org_sec(p.org_id,p.business_group_id),
xxx.get_org_div(p.org_id,p.business_group_id)
Thanking in advance
Something like this.
SQL> select * from emp
2 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DIV
7369 SMITH CLERK 7902 17-DEC-80 800 20 10
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 10
7566 JONES MANAGER 7839 02-APR-81 2975 20 10
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 10
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 10
7839 KING PRESIDENT 17-NOV-81 5000 10 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 10
7876 ADAMS CLERK 7788 23-MAY-87 1100 20 10
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DIV
7900 JAMES CLERK 7698 03-DEC-81 950 30 10
7902 FORD ANALYST 7566 03-DEC-81 3000 20 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 10
14 rows selected.
SQL> select div,sum(emp) total, max(decode(deptno,10,emp)) ten, max(decode(deptno,20,emp)) twenty, max(decode(deptno,30,emp)) thirty
2 from (select sum(empno) emp, div, deptno
3 from emp
4 group by div, deptno)
5 group by div
6 /
DIV TOTAL TEN TWENTY THIRTY
10 108172 23555 38501 46116
SQL>thanks,
Karthick.
Similar Messages
-
How to merge rows with similar values in alv grid display in webdynpro
Hi experts,
i want to know about how to merge rows with similar values in alv grid display of webdynpro.grouping rows is possible in table display in webdynpro but i am not able to do row grouping in the alv grid display in webdynpro.
kindly suggest.
thanks ,
Anita.Hi Anita,
did you find a solution for this? I have opened a Thread, if you know the answer maybe you could help me out:
Is there an ALV function similar to the TABLE Row grouping?
Thanx in advanced!!!
Kind Regards,
Gerardo J -
hello everyone, im having a problem woth my ALV, how can i merge rows in ALV,
example i want to merge row 3 and row 4?
Another 1 how can I format a certain row in ALV?
example row 5, I want the displayed value be centered, or right aligned, or left aligned...
thank you very muchChristopher,
I am not sure what is the functionality you are trying to achieve by merging rows. If you SORT the rows, there should be a option (Iam not sure whether it is in the field catalog or the layout most probably in the layout), where the rows with the same for specific columns will automatically get merged. However, it does not make sense if the entire row is duplicated. You probably can delete the adjacent duplicates by sorting the table even before displaying the data.
I am not sure the formatting that you are asking, but you can trying passing different values to LVC_T_STYLE type table which has to be a part of you data internal table. So, for a specific row, you append the column names and the specific style that you want for individual columns.
Regards,
Ravi
Note : Please reward points if this helps you. -
How can I merge rows together to go from this:
1
2
3
A
F
A
G
A
D
H
B
I
B
J
C
K
C
L
C
M
C
E
N
To this:
1
2
3
A
D
F, G, H
B
I, J, K
C
E
L, M, NTry VBA code:
Sub Test()
Dim d1 As Object, d2 As Object, d3 As Object, i%, arr
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
For i = 2 To UBound(arr)
For j = 2 To Application.CountA(ActiveSheet.Range("1:1"))
d1(arr(i, 1)) = ""
d2(arr(1, j)) = ""
d3(arr(i, 1) & arr(1, j)) = d3(arr(i, 1) & arr(1, j)) & arr(i, j)
Next
Next
Range("B16").Resize(1, d2.Count) = d2.keys
Range("A17").Resize(d1.Count, 1) = Application.Transpose(d1.keys)
For i = 17 To d1.Count + 16
For y = 2 To d2.Count + 1
If d3.exists(Cells(i, 1) & Cells(16, y)) Then
Cells(i, y) = d3(Cells(i, 1) & Cells(16, y))
End If
Next
Next
End Sub
Wind Zhang
TechNet Community Support -
Macro/VBA script to merge rows with same values in another column
Hi.
I'm developing a dance competition application, using Excel 2010, and have so far managed to put judges' marked scores into a worksheet through a userform.
Now I would like to make the worksheet more presentable as a scoreboard, as you would manually, but via VBA scripts.
Exhibit Numbers (Column G) are unique identifiers (per competition) for contestants and each contestant is typically judged by three judges. The scores in three separate categories from one judge would spread in one row so each contestant would have three
rows.
I would like to merge rows of columns where the totals from the judges go (Columns P to U) for each contestant.
I've considered using some kind of loop but I don't have enough experience in vba scripting, it gets overcomplicated. Could someone please help?
Many thanks.
Maki Koyama (Canberra, AUS)Hi,
You cannot add a static "Y" inside a when looping over "i". You need to ensure that "Y" changes along with X. Try the modified code below.
List elements = new ArrayList();
for (int i=0; i<XXX; i++) {
IZZZ.IVisibilityElement el = wdContext.createVisibilityElement();
el.setVisAttr(i); // Change Y to i
elements.add(el);
wdContext.nodeVisibility().bind(elements);
That should give you an idea of what is erroneous in the code.
Thanks.
HTH.
p256960 -
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. -
Importstring with xml merging row data
I have a simple XML import I'm trying to do, rather than manually parsing the data. There's a problem though. The following XML generates 3 rows in the datawindow instead of 4. I'm using a default template.
<?xml version="1.0"?><dw_tqxml>
<dw_tqxml_row><dosetime>AM</dosetime><qty>1</qty></dw_tqxml_row>
<dw_tqxml_row><dosetime>8pm</dosetime><qty>1.25</qty></dw_tqxml_row>
<dw_tqxml_row><dosetime>NOON</dosetime></dw_tqxml_row>
<dw_tqxml_row><qty>3.00</qty></dw_tqxml_row>
</dw_tqxml>
The first and second rows come out fine, the third row is a combination of the two last rows.
Here's the result data
"AM", "1"
"8pm", "1.25"
"NOON", "3.00"
dw sql is:
select space(10) as dosetime, space(10) as qty from dummy
It's my understanding that missing data should use the default values in the datawindow.
PB 12.5 Build 5583
Anyone have any ideas on why it's merging rows? This is the first time I've used XML import, don't really have a clue what I'm missing.I have limited experience with XML import. What I have just found is:
Column tag names are ignored during import.
The import "finds" the data between each detail item.
Appears to completely ignore the surrounding "row" tags.
Your XML file needs empty detail tags when there is no data. No PowerBuiilder import function will assign default values. Only InsertRow() function does that.
XML imports/exports works really well with nested or composite datawindows. There are templates generated that you can use. Not sure how templates work. -
select OPRCLASS,BUSINESS_UNIT from ps_sec_bu_cls where oprclass like 'OHRL_ADA01%';
OPRCLASS BUSINESS_UNIT
OHRL_ADA01 ADA01
OHRL_ADA01 PRT01
OHRL_ADA01 STATE
How can i merge all the BUSINESS_UNIT rows into one row with a delimiter?
OPRCLASS BUSINESS_UNIT
OHRL_ADA01 ADA01, PRT01, STATEOne possible solution: STRAGG
-
Merging rows in template output
Hello all.
I have a requirement
I have customer name repeating in few rows...My client would like to see those cells merged as repeating customer name is looking messy(Template is RTF, Output is Excel).
Some thing like in the below picture:
http://i54.tinypic.com/33a47q9.jpg
is it something that can be implemented in BI Publisher?
Thanks in advance !Hi,
For you requirement, u must have placed all te for loops that is for customer, selling code and amount initially at the starting of the table.
Now what you need to do is to use only the variable customer initially in the for loop. and then , inside that table u need to create other table for selling code and amount, and use remaining 2 for loops over there.
and after the end of these 2 for loops of selling code and amount: u can write the XML code for summing up of amount [sum(current-group()/<<tag>>)]. -
Merge rows in a single excel sheet
I have an excel workbook(A) and its copy (B). Both contain one sheet only.
In A, Rows 1-15 are filled. In B Rows 16-30 are filled.
How can I perform an automated merge of A and B files without using manual copy paste ? i.e copy rows 16-30 from B file to A file. The
merged file will now contain all 30 rows filled.
Please help.Hi,
If you want to copy data from one workbook to another workbook data, the following code you can refer to:
Sub DopyExcelData()
Dim wkbk As Workbook
Set wkbk = Workbooks.Open("D:\test2.xlsx")
'D:\test2.xlsx is my another excel workbook
wkbk.Activate
Sheets("Sheet1").Activate
Range("A1:C15").Select
Selection.Copy
wkbk.Close False
Range("A16").Select
ActiveSheet.Paste
MsgBox "OK"
End Sub
Hope this will help you
Best Regards
Lan
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Merge rows in report in OBI EE
hi,
i am using OBI EE to generate reports on dashboard.
i have 4 columns to display different values. i have case statements in all the 4 columns. i am substituting null if no conditions are satisfied. however, the results obtained are duplicated in the number of rows. For Ex: if the condition in the first column is displayed, the rest columns are null. The 2nd row is nothing but null value in the 1st column but values in the 2nd column. The 3rd row is null values in the first 2 columns but actual value in the 3rd column and so on...
My requirement is to generate 1 single row, with the data in all the columns.
can you please help me out on this?Hi,
If you want to copy data from one workbook to another workbook data, the following code you can refer to:
Sub DopyExcelData()
Dim wkbk As Workbook
Set wkbk = Workbooks.Open("D:\test2.xlsx")
'D:\test2.xlsx is my another excel workbook
wkbk.Activate
Sheets("Sheet1").Activate
Range("A1:C15").Select
Selection.Copy
wkbk.Close False
Range("A16").Select
ActiveSheet.Paste
MsgBox "OK"
End Sub
Hope this will help you
Best Regards
Lan
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Howdy all,
Given the following data set...
ID GROUP_ID AWESOME MOD_DATE LAST_NAME FIRST_NAME
52 98 1 2/1/2011 Kirk James
60 99 1 2/2/2011 Kirk James
42 45 0 1/29/2011 Kirk James
100 31 1 6/24/2011 Smurf Papa
200 32 1 6/23/2011 Smurf Papa
300 33 0 6/22/2011 Smurf Papa
400 34 0 6/21/2011 Smurf Papa for those with the same last_name and first_name,
where AWEAOME=0,
I want to overwrite their GROUP_ID with the grou_ID where AWESOME=1
and the latest DOM_DATE.
So for James Kirk, his group_id of 45 will be set the 99
and for Papa Smurf, his group_ids of 33 and 34 will be set to group_id 31
Desired result
ID GROUP_ID AWESOME MOD_DATE LAST_NAME FIRST_NAME
52 98 1 2/1/2011 Kirk James
60 99 1 2/2/2011 Kirk James
42 99 0 1/29/2011 Kirk James
100 31 1 6/24/2011 Smurf Papa
200 32 1 6/23/2011 Smurf Papa
300 31 0 6/22/2011 Smurf Papa
400 31 0 6/21/2011 Smurf Papa thanksSomething like
UPDATE table_name dest
SET group_id =
(SELECT group_id
FROM (
SELECT group_id,
mod_date,
first_name,
last_name,
max( mod_date ) over (partition by last_name, first_name) last_mod_date
FROM table_name src_inner
WHERE src_inner.awesome = 1 ) src_outer
WHERE src_outer.last_mod_date = src_outer.mod_date
AND src_outer.first_name = dest.first_name
AND src_outer.last_name = dest.last_name )
WHERE awesome = 0;should work. This assumes that there is always at least 1 row where AWESOME=1 and the name matches for every row where AWESOME=0. And it assumes there are no duplicates where the same name with AWESOME=1 have the same maximum MOD_DATE.
Justin -
Hi
I have a table with
col1 col2 col3 col4 col5
A B 9 NULL NULL
A B NULL 9 NULL
A B NULL NULL 9
My resultset should display like in a single row
A,B,9,9,9
Any helpDear Alish!
Please have a look at this example.
WITH s AS
(SELECT 'A' as col1, 'B' as col2, 9 as col3, NULL as col4, NULL as col5 ROM dual
UNION ALL
SELECT 'A', 'B', NULL, 9, NULL FROM dual
UNION ALL
SELECT 'A', 'B', NULL, NULL, 9 FROM dual)
SELECT col1, col2,
MIN(DECODE(col3, 9, 9, NULL)) as col3,
MIN(DECODE(col4, 9, 9, NULL)) AS col4,
MIN(DECODE(col5, 9, 9, NULL)) AS col5
FROM s
GROUP BY col1, col2
C C COL3 COL4 COL5
A B 9 9 9Yours sincerely
Florian W. -
Combining/ merging rows in PowerPivot
Hi,
Currently what happens is when I create a Pivot Table based on the first table I get count for ABC10 as 2, but ideally it should be 1. I want to combine Sub Bill Type if BILL NO and BILL TYPE is same. Ideally second row shouldn't be considered into calculation,
but should include SUB BILL TYPE.
Is there any formula to achieve this?
I am not a query expert, so no idea if it's possible using query. Recently I am using this query.
SELECT AL1.BILL_NO as "Bill No", AL1.REF_NO as "Ref No", AL1.REF_MOD as "Reference Module",
AL1.STATUS "Bill Status", AL1.PAYER_NAME as "Payer Name", AL1.BILLING_DT as "Billing Date",
AL1.DUE_DT as "Due Date", AL1.ID_TYPE as "ID Type", AL1.ID_NO as "ID No",
AL1.REMARKS as "Remarks", AL4.FEELIST_ID as "FeeList ID",
AL4.FEE_ID as "Fee ID", AL4.QUANTITY as "Quantity", AL4.GST_AMT as "GST Amount",
AL4.GST_ABSORBED as "GST Absorbed", AL4.SUBTOTAL as "Sub Total", AL3.BILL_TYPE as "Bill Type",
AL3.SUBBILL_TYPE as "Sub Bill Type", AL3.AMOUNT as "Amount", AL2.PAY_ID as "Pay ID",
AL2.PAYMENT_MODE as "Payment Mode", AL2.PAY_STATUS "Pay Status",
AL2.CHQ_ID as "Cheque ID", AL2.RECEIPT_NO as "Receipt No", AL2.COLLECTION_CTR as "Collection Centre",
AL2.PAYMENT_DT as "Payment Date", AL2.PAID_AMOUNT as "Paid Amount",
AL2.TRANS_DT as "Transaction Date", AL5.WORKPLACE_NAME as "Workplace Name"
FROM BIL_BILL AL1, BIL_PAY AL2, BIL_BILLING_FEE AL3, BIL_FEELIST AL4, LIC_WP_DET AL5
WHERE (AL1.BILL_NO = AL4.BILL_NO (+) AND AL1.REF_NO = AL5.WORKPLACE_NO (+) AND
AL1.BILL_NO=AL2.BILL_NO AND AL4.FEE_ID=AL3.FEE_ID) AND (AL2.PAY_STATUS='PD' AND
AL1.DELETE_IND='F' AND AL2.DELETE_IND='F')
Thanks,
SSHi ,
Please check out the below link for the solution in Power Pivot
Group Multiple Rows to Single Delimited Row in PowerPivot
For achieving this in SQL , check the below link. This will work for SQL server. But your query looks like Oracle one.
TSQL – Concatenate Rows using FOR XML PATH()
Best Regards Sorna -
Merge rows in REUSE_ALV_LIST_DISPLAY
Hi Friends,
I have used REUSE_ALV_LIST_DISPLAY FM to display my report.
I have a scenario wherein if there are more than one Raw material for a single Finished Good than I need to display the raw materials in the same raw one after the other.
Fin.Goods Raw Material
100165 300001
<blank> 300002
<blank> 300003
1000166 300001
<blank> 300005
Thanks,
Anu.
Edited by: Anuradha Edachali on Mar 24, 2010 3:34 PMUse
WA_SORT-TABNAME = 'IT_OUTPUT'.
WA_SORT-FIELDNAME = 'PR_NO'. " Field Name
WA_SORT-UP = 'X'.
WA_SORT-GROUP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
then use that in alv display like
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'
I_GRID_TITLE = 'Project SO Details (FAS)'(003)
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
IT_SORT = IT_SORT
IT_FILTER = IT_FILTER
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = IT_OUTPUT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Maybe you are looking for
-
ITunes quit working on Windows 7 PC - UGH
First of all, I don't sync with iTunes that often, mainly because my iTunes library is a mess. And because of the mess, I purchased the Tuneup app to help me clean it all up. Immediately after downloading the app, nothing at all worked. Both iTunes a
-
How do I fix the "Invalid Signature" problem?
I keep getting this error message everytime I try to update my software to 10.6.3. I've even tried the suggestion of a manual download and it still says the same thing. Does it make any difference to say that my iTunes and accompanying music are save
-
Note: Mac OS X 10.5 Leopard & Adobe Creative Suite CS2
Hello, here is an important note for Apple & Adobe business users who are using the Adobe Creative Suite CS2 package for their daily workflow. http://www.adobe.com/go/leopardfaq <--- quote from Adobe ---> Question: Will older versions of Adobe creati
-
I recently purchased Adobe Photoshop Elements 11 an downloaded it, but it will not open. I receive a message that states that I need to 'uninstall' and then to 'reinstall'. How do I do this and where is the software available again to reinstall? Th
-
Purchase Requsition Delivery Date
In APO in which table i can find the field Delivery date for a purchase req number