Need Help in Pivot of the Columns in Oracle 9i
Hi,
I have a requirement where-in i need to generate the output as below:<<under EXP1 we need to populate the SUM amounts for each category i.e. group by No and Category>>
No Vessel EXP1 EXP2 EXP3 EXP3 .....
1 TEST 10 -8 100 0
2 TEST 11 0 90 -17
And the Code I am using for the same as below:
SELECT Vessel_Code,
dano,
join(cursor(select 'SUM(DECODE(ExpenseCategory,'||''''||expensecategory||''''||',GroupAmount,NULL))'||' '||expensecategory
from linetypes
where ExpenseCategory NOT IN ('ADV','BANKCHARGES','GAIN/LOSS','NONAGENT')
and ExpenseCategory NOT LIKE 'REBILLABLE%'
and ExpenseCategory NOT LIKE 'SPECIFIED%'
group by expensecategory))
FROM
(select a.Vessel_Code
, NVL(a.ParentDANo,a.DA_NO) as dano
, b.ExpenseCategory
, sum(NVL(FinalDAAMount,0)+NVL(supplmnt_amount,0)) as GroupAmount
from da_head a
Cross Join LineTypes b
Left Join DA_Detail c
On a.DA_No = c.DA_No
and a.Credit_Status = c.Credit_Status
and b.DALineTypeId = c.DA_LINETYPE_ID
where status in ('P','G')
and b.ExpenseCategory NOT IN ('ADV','BANKCHARGES','GAIN/LOSS','NONAGENT')
and b.ExpenseCategory NOT LIKE 'REBILLABLE%'
and b.ExpenseCategory NOT LIKE 'SPECIFIED%'
Group by a.Vessel_Code
, NVL(a.ParentDANo,a.DA_NO)
, b.ExpenseCategory
Union
select a.Vessel_Code
, NVL(a.ParentDANo,a.DA_NO) as dano
, SUBSTR(b.ExpenseCategory,0,Length(b.ExpenseCategory)-1) as ExpenseCategory
, sum(NVL(FinalDAAMount,0)+NVL(supplmnt_amount,0)) as GroupAmount
from da_head a
Cross Join LineTypes b
Left Join DA_Detail c
On a.DA_No = c.DA_No
and a.Credit_Status = c.Credit_Status
and b.DALineTypeId = c.DA_LINETYPE_ID
where status in ('P','G')
and b.ExpenseCategory NOT IN ('ADV','BANKCHARGES','GAIN/LOSS','NONAGENT')
and b.ExpenseCategory LIKE 'SPECIFIED%'
Group by a.Vessel_Code
, NVL(a.ParentDANo,a.DA_NO)
, SUBSTR(b.ExpenseCategory,0,Length(b.ExpenseCategory)-1)
Union
select a.Vessel_Code
, NVL(a.ParentDANo,a.DA_NO) as dano
, SUBSTR(b.ExpenseCategory,0,Length(b.ExpenseCategory)-1) as ExpenseCategory
, sum(NVL(FinalDAAMount,0)+NVL(supplmnt_amount,0)) as GroupAmount
from da_head a
Cross Join LineTypes b
Left Join DA_Detail c
On a.DA_No = c.DA_No
and a.Credit_Status = c.Credit_Status
and b.DALineTypeId = c.DA_LINETYPE_ID
where status in ('P','G')
and b.ExpenseCategory NOT IN ('ADV','BANKCHARGES','GAIN/LOSS','NONAGENT')
and b.ExpenseCategory LIKE 'REBILLABLE%'
Group by a.Vessel_Code
, NVL(a.ParentDANo,a.DA_NO)
, SUBSTR(b.ExpenseCategory,0,Length(b.ExpenseCategory)-1)
GROUP BY Vessel_Code,
dano
order by dano;The reason why I have been using the join(cursor(.....) to get the result set as :
SUM(DECODE(ExpenseCategory,'OWNER',GroupAmount,NULL)) OWNER,
SUM(DECODE(ExpenseCategory,'CTM',GroupAmount,NULL)) CTM,
SUM(DECODE(ExpenseCategory,'PORT',GroupAmount,NULL)) PORT,
SUM(DECODE(ExpenseCategory,'REBILLABLE',GroupAmount,NULL)) REBILLABLE,
SUM(DECODE(ExpenseCategory,'SPECIFIED',GroupAmount,NULL)) SPECIFIED,
SUM(DECODE(ExpenseCategory,'CARGO',GroupAmount,NULL)) CARGO,
SUM(DECODE(ExpenseCategory,'ACCTTEMP',GroupAmount,NULL)) ACCTTEMPAs we don't know the exact number of expense categories to be displayed I have used cursor excluding the expense categories I don't need.When I run the same as individual query I get the correct result but when I execute it along with the query I get error maximum cursors open exceeded...
Please let me know how can it be achieved.
Any suggestions are welcome.
Thanks,
Hemanth
The easiest way to do this, and it could be done in a few minutes, would be to move to a currently supported version of Oracle, 11gR1 or 11gR2, where we have the PIVOT and UNPIVOT operators.
In the desupported version you have the best choice is to hit http://asktom.oracle.com and look up the solution he published there some years ago.
I don't have the link so you can find it as fast as I can but look under "pivot" and "crosstab."
Similar Messages
-
Need help with Pivoting rows to columns
Hi,
I need help with pivoting rows to columns. I know there are other posts regarding this, but my requirement is more complex and harder. So, please give me a solution for this.
There are two tables say Table 1 and Table 2.
Table1
name address email identifier
x e g 1
f s d 2
h e n 3
k l b 4
Table2
identifier TRno zno bzid
1 T11 z11 b11
1 T12 z12 b12
1 T13 z13 b13
2 T21 z21 b21
2 T22 z22 b22
As you can see the identifier is the column that we use to map the two tables. The output should be like below
output
name address email identifier TRno1 zno1 bzid1 TRno2 zno2 bzid2 TRno3 zno3 bzid3
x e g 1 T11 z11 b11 T12 z12 b12 T13 z13 b13
f s d 2 T21 z21 b21 t22 z22 b22
Also we do not know exactly how many TRno's, zno's, etc each value in the identifier will have. There may be only 1 TRNO, zno and bzid, or there may be four.
All the values must be in separate columns, and not be just comma delimitted. There are also other conditions that i have to add to restrict the data.
So, can you please tell me what is should use to get the data in the required format? We are using Oracle 10g. Please let me know if u need any more informationSomething like this ?
SCOTT@orcl> ed
Wrote file afiedt.buf
1 select a.name,
2 a.address,
3 a.email,
4 b.* from (
5 select distinct identifier
6 ,max(trno1) trno1
7 ,max(zno1) zno1
8 ,max(bzid1) bzid1
9 ,max(trno2) trno2
10 ,max(zno2) zno2
11 ,max(bzid2) bzid2
12 ,max(trno3) trno3
13 ,max(zno3) zno3
14 ,max(bzid3) bzid3
15 ,max(trno4) trno4
16 ,max(zno4) zno4
17 ,max(bzid4) bzid4
18 from (select identifier
19 ,decode(rn,1,trno,null) trno1
20 ,decode(rn,1,zno,null) zno1
21 ,decode(rn,1,bzid,null) bzid1
22 ,decode(rn,2,trno,null) trno2
23 ,decode(rn,2,zno,null) zno2
24 ,decode(rn,2,bzid,null) bzid2
25 ,decode(rn,3,trno,null) trno3
26 ,decode(rn,3,zno,null) zno3
27 ,decode(rn,3,bzid,null) bzid3
28 ,decode(rn,4,trno,null) trno4
29 ,decode(rn,4,zno,null) zno4
30 ,decode(rn,4,bzid,null) bzid4
31 from (select identifier,
32 trno,bzid,zno,
33 dense_rank() over(partition by identifier order by trno,rownum) rn
34 from table2)
35 order by identifier)
36 group by identifier) b,table1 a
37* where a.identifier=b.identifier
SCOTT@orcl> /
NAME ADDRESS EMAIL IDENTIFIER TRNO1 ZNO1 BZID1 TRNO2 ZNO2 BZID2 TRNO3 ZNO3 BZID3 TRNO4 ZNO4 BZID4
x e g 1 T11 z11 b11 T12 z12 b12 T13 z13 b13
f s d 2 T21 z21 b21 T22 z22 b22
SCOTT@orcl> select * from table1;
NAME ADDRESS EMAIL IDENTIFIER
x e g 1
f s d 2
h e n 3
k l b 4
SCOTT@orcl> select * from table2;
IDENTIFIER TRNO ZNO BZID
1 T11 z11 b11
1 T12 z12 b12
1 T13 z13 b13
2 T21 z21 b21
2 T22 z22 b22
SCOTT@orcl>Regards
Girish Sharma -
Need help in double click the column in ALV
hello all ,
I am new to Abap coding . I have got the following requirement .
there are 2 columns in my alv grid output list . First column shows both the sales orders and Quotation .
2nd column shows the document type ..If the document type is ZQT then that is recognised as Quotation . For the remaining documnets types all are sales orders. Please see sample list ..
Salesorder/quotation | Document type
| -
| -
| ZQT
| -
| -
So if the users double clicks on Sales order it has to go to VA02 transaction .
If the user double clicks on quotationin that same column it has to go to VA22 transaction .
Please tell me how to achieve thisfunctionality in the same column .
ThanksAs per your requirement i put one example so it will help to solve your issue
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-cfieldname = &3.
ls_fieldcat-qfieldname = &4.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
TYPES:
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
waerk TYPE vbak-waerk, " Currency
END OF ty_vbak,
BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln, " Sales document
posnr TYPE vbap-posnr, " Sales document item
matnr TYPE vbap-matnr, " Material number
arktx TYPE vbap-arktx, " Short text for sales order item
kwmeng TYPE vbap-kwmeng, " Order quantity
vrkme TYPE vbap-vrkme, " Quantity Unit
netwr TYPE vbap-netwr, " Net value of the order item
waerk TYPE vbap-waerk, " Currency
END OF ty_vbap.
DATA :
gs_vbak TYPE ty_vbak,
* Data displayed in the first list
gt_vbak TYPE TABLE OF ty_vbak,
* Data displayed in the second list
gt_vbap TYPE TABLE OF ty_vbap.
SELECT-OPTIONS :
s_vkorg FOR gs_vbak-vkorg, " Sales organization
s_kunnr FOR gs_vbak-kunnr, " Sold-to party
s_vbeln FOR gs_vbak-vbeln. " Sales document
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
v_1 = 'Maximum of records to read'.
START-OF-SELECTION.
PERFORM f_read_data_vbak.
PERFORM f_display_data_vbak. -
I actually need help but cannot find the answer.
Please.......Lately when open a new tab it does not open with a blank page. I don't want to set my homepage as blank as when I first open Firefox, it automatically loads my hotmail page. But then if I open other pages I don't get a blank page. Help, please?
Thank you.
''[Personal information removed by moderator. Please read [[Forum and chat rules and guidelines]], thanks.]''hello, please refer to [[New Tab Page – show, hide and customize top sites]] in order to switch the feature off.
-
I buy for mac app but not for the iPad, so how do I reinstall a program that has already purchased? I need help because I bought the imovie'11 but when he opened it only brought 8 movie trailer templates instead of the 15 it says on the program. How do I solve this problem? Once paid for a program incomplete. I also liked that the AppStore itself had a button to reinstall programs already bought, because it is very hard to understand how to do this in the store, only option is to install and hide purchase, and how do I reinstall, attention'm talking about reinstalling a computer mac, not an ipad or iphone.
Thank you.Prodesigntools.com , go ahead and download the software from there and use your serial number to serialize it.
-
I get the following message when trying to open an .avi downloaded from my video cam, need help, can not find the codec, thank you. This is for Quicktime Player.
"The document “IMAG0026.AVI” could not be opened. A required codec isn't available."Try Perian.
http://perian.org/ -
I need help in finding all the new fontsin iPad 2 using iOS 5
I need help in finding all the new fonts in ipad 2 using ios 5
You cannot change the email font. You can make it bold, italics and underline the type, but Helvetica is your only choice in the mail app.
In the notes app you have 3 choice Noteworthy, Helvetica and Marker Felt. The font can be changed in Settings>Notes>Font.
You can only use fonts that are built into the app that you are using at the time. You cannot pick and choose fonts from a list of all of the fonts that may be on the iPad but only from the list of fonts that the app allows. -
Yosemite made my MacBook Pro so slow !! Need help ? what is the solution?
Yosemite made my MacBook Pro so slow !! Need help ? what is the solution?
I've ran a benchmark on my Mac (iMac early 2009). Performance of Yosemite in general was about the same as Mavericks. But that can be different on other Mac's of course. Safari is mostly a bit slower. It's recommended you clean your old internet-caches and then restart Safari. (you can use a little app called CCleaner to do that). That might make a difference. Speed-issues are usually solved in the first and second update of OS X.
-
I need help! I updated the new 6.1.3 last night. Since that time my phone will not charge. The phone is plugged in and shows as charging but the battery still drains. What can I do? I need help!
Restore iPhone with iTunes on your computer.
-
I need help quick please sold the iPod and before handing it over wanted to clear out info so pushed erase now there is only a plug icon for iTunes but it won't now recognize my computer what can I do??
Try
iOS: Device not recognized in iTunes for Windows
or
iPhone, iPad, iPod touch: Device not recognized in iTunes for Mac OS X -
I had to put my computer by together without migration or time machine I NEED help with order of the files?
Hi, where are these other files exactly?
-
Need help with passcode using the "Remote" app
Hello and thanks in advance. I can't find a place on iTunes to enter the passcode from the Remote app.
PLEASE READ!!!
I have a HP Pavilion - Windows XP
I need help as well with the passcode. I went to Networking and Sharing center and clicked customize and changed the name to NetGear because that is what it says next to my WiFi on my iPhone but with my iPhone under Settings it says WiFi NETGEAR > but when I click on it, it says choose a Network. Is NETGEAR a network? How do I find or change to a Network? is this the problem? -
I Need help!!! The card I used when I first set up my account I lost it so now I can't download any music cause it's wanting a number off that card and I don't have it anymoe... Someone tell me what to do please???
Add another good card and delete the old one, Yu can also purchase and redeem an iTunes gift card and hthen delee the bad credit card. Yu need a valid payment method for update as well even purchasing free apps if the account was set up with a credit card.
-
I need help! I have the iphone 5 and I want to buy the whastsaap, but it turns out I get to put the answers up and answer the questions but I do not remember. Someone could help me? Help! Thank you!
Security questions:
https://discussions.apple.com/thread/4533485?tstart=0 -
Cannot open Photoshop?? Need help. I got the creative Cloud.
Cannot open Photoshop?? Need help. I got the creative Cloud.
Mee too it works.. im really happy
Am 01.10.2014 19:42, schrieb sam.am:
>
Cannot open Photoshop?? Need help. I got the creative Cloud.
created by sam.am <https://forums.adobe.com/people/sam.am> in /Adobe
Creative Cloud/ - View the full discussion
<https://forums.adobe.com/message/6781543#6781543>
Maybe you are looking for
-
'All' filter in Obiee 11g dashboard
Hi All, My client requirement is to see all data in dashboard prompt as well as there should be another item its 'ALL' which return the all data. Example: There is a dashboard filter on CustomerType (like: GOLD,SILVER) , our client want to see the da
-
Hi Friends! 1) Could u pls tell me when to use BDC & When to use LSMW I am a technical Person i want to load data using LSMW Then when to do that? apart from doent need programming effort. 2) My Second Doubt is From LSMW, Suppose i am doing lsmw i
-
How do I open music after moving files from 1 drive to another?
I ran out of disk space on my C drive. The computer is partitioned w/ C & D drives. I moved all itunes folders to the D drive and cannot open the music. I went to advanced and redirected to the D drive and appropriate file without any luck. Signed Tu
-
How do you upgrade from PowerMac 10.4.11?
Is it possible to upgrade a PowerMac 10.4.11 to 10.6.11 or higher. If so, what are the proceedures, and methods of doing this. Or I am just stuck with an obsolete computer? Am I new to the apple world, and any help would be greatly appreciated.
-
HELP!!!! My BB 8700g has gone haywire!!
I downloaded a theme off the browser and now my bb turns on, shows the busy signal, signal turns around twice, and the turns off again. I tried taking out the battery and doing a hard reset, but it is not working. HELP!!! PLEASE!!!! Does this thing h