Issue with how to compute additional column in query output.

Hello PL/SQL Gurus/experts,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
Currently i have the data in the following way -
drop table T2;
create table T2(Year, MastTot, BechTot, Tot) as select
'2008', '20000', '450000', '470000' from dual union all select
'2008', '50000', '324000', '374000'  from DUAL union all select
'2009', '25000', '450000', '475000'  from dual union all select
'2009', '250000', '324000', '574000' from DUAL union all select
'2010', '120000', '450000', '570000' from dual union all select
'2010', '52000', '324000', '376000'  from DUAL union all select
'2011', '220000', '450000', '670000' from dual union all select
'2011', '52000', '324000', '376000'  from DUAL ;I want the data to be presented in the following way (output)-
Year     MastTot     %Change     BechTot     %Change     Tot     %Change     %Total
2009     275000     292.86     774000     0     1049000     24.29     27
2010     172000     -37.45     774000     0     946000     -9.82     24.35
2011     272000     58.14     774000     0     1046000     10.57     26.92
Total     789000     313.54     3096000     0     3885000     25.04     78.28I am using the following sql query -
select decode(grouping(Year), 0, Year, 'Total') Year,
       To_Char(sum(MastTot), '999,999,999,999,999,999,999.99')  "MastTot",
       To_Char(sum(BechTot), '999,999,999,999,999,999,999.99')  "BechTot",
       To_Char(sum(Tot), '999,999,999,999,999,999,999.99')  "Tot",
       round((sum(Tot)/nullif(max(total_amount),0)) * 100, 2) "%Total"
  From
select Year,
       sum(MastTot) MastTot,
       sum(BechTot) BechTot,
       sum(Tot) Tot,
       SUM(Tot) over() total_amount
  From t2
group by Year,Tot
where Year>'2008'
group by grouping sets((Year),())
order by YearBut i am not able to fetch the %Change column. Kindly help me with that.
All efforts and help in this regard is highly appericated and i will be thankful to you ...

Hello Purvesh K/jeneesh
If data turn out to the be following -
drop table T2;
create table T2(Year, MastTot, BechTot, Tot) as select
'2008', '20000', '450000', '470000' from dual union all select
'2008', '50000', '324000', '374000'  from DUAL union all select
'2009', '25000', '450000', '475000'  from dual union all select
'2009', '250000', '324000', '574000' from DUAL union all select
'2010', '120000', '0', '570000' from dual union all select
'2010', '52000', '0', '376000'  from DUAL union all select
'2011', '220000', '450000', '670000' from dual union all select
'2011', '52000', '324000', '376000'  from DUAL ;and if i use the following sql -
select year, sum(masttot), sum(change), sum(bechtot), sum(b_change), sum(tot), sum(t_change)
  from (
          select lead(year) over(order by year) year,
                 lead(masttot) over (order by year) masttot,
                 round((lead(masttot) over (order by year) - masttot)/nullif(masttot,0), 4) * 100 Change,
                 lead(bechtot) over (order by year) bechtot,
                 round((lead(bechtot) over (order by year) - bechtot)/nullif(bechtot,0), 4) * 100 B_Change,
                 lead(tot) over (order by year) tot,
                 round((lead(tot) over (order by year) - tot)/nullif(tot,0), 4) T_Change
            from (
                  select year, sum(masttot) masttot, sum(bechtot) bechtot, sum(tot) tot
                    from t2
                   group by year
                   order by year
       ) a
where year is not null
group by yearor
with t
as (
select year,masttot,lag(masttot) over(order by year) prevm,
BechTot,lag(BechTot) over(order by year) prevb,
tot,lag(Tot) over(order by year) prevt,
sum(tot) over(order by null) sm_t
from(
select Year,
sum(MastTot) MastTot,
sum(BechTot) BechTot,
sum(Tot) Tot
From t2
group by Year
select year,sum(masttot) masttot,
sum(((masttot-prevm)/nullif(prevm,0))*100) Perc_m,
sum(BechTot) bechtot,
sum(((BechTot-prevb)/nullif(prevb,0))*100) Perc_b,
sum(tot) tot,sum(((tot-prevt)/nullif(prevt,0))*100) Perc_t,
sum((tot/nullif(sm_t,0))*100)  perc_total
from t
where year > 2008
group by rollup(year);then it is not giving the correct result as in case of 2010 to 2011 in %B (Bechelor) total there is 100% change as from in year 2010 sum(bechtot)=0 and in year 2011 it is 774000.
Whats wrong with this ..........
Thanks in advance for your help/effort and valuable
Edited by: user555994 on Oct 15, 2012 5:24 AM

Similar Messages

  • How to avoid blank column display in output in ALV TREE

    how to avoid blank column display in output while decreasing the length of other columns in ALV Tree.
    Example: please refer to BCALV_TREE_01 and see the output, then decrease the length of all columns . Then you can see a blank column appearing in screen at last, i.e in container. so how to avoid that.
    Thanks for reply.
    Edited by: morpeous on Jul 1, 2009 1:53 PM

    Hi,
    Check BCALV_TREE_02 on how to hide columns.
    Thanks & Regards,
    Anand Patil

  • E1200 router connectivity issue with windows 7 computer from sleep state over night

    recently purchased the e1200 and setup was a breeze but I'm  having difficulty with the primary computer (windows 7) connected to it, by wire, haven't used any wireless yet.  When the computer is put to sleep through the night, I have to restart the computer the next morning to get a signal but works fine if put to sleep during the day and awakened the same day to use the connection.  Have a second computer wired directly to the modem with vista that doesn't have this issue.  any thoughts out there. thanks

    Try this. Go to Control Panel>Click on Network and Sharing Center or Network and Internet and then Network and Sharing Center>Click on Change Adapter settings>Right Click on Local Area Connection (the adapter being used for the wired connection)>Click on Properties>Click in Configure>Go to the Power Management tab>Uncheck "Allow the computer to turn off the device to save power"

  • Noticed some issues with how NI DNET card handles problems

    We have
    noticed 2 issues with using the PXI NI-DNET (PXI-8461) card and Labview (8.5).
    1.  The scanner doesn’t recover from a lost of
    DNET power
    - With network
    work up and everything scanning
    - The Dnet
    DC power is turned off and then turned back on
    -  All nodes are rest from the power cycle which
    is common
    - However,
    when we try to scan the network again, Labview faults with can’t initialize card
    I believe
    - No nodes
    restart
    The DNET
    card seems to not be monitoring the network DC power and releasing the handles
    and/or trying to rescan the attached nodes.
    Work
    around: Restart the PXI or in Max, remove and reinstall DNET card
    The work around are not a good solution.  Is there another solution and why isn't the card restarting. 
    2.  When Labview locks up, the DNET card keeps
    scanning.  When this happens the last
    setpoints are still being sent.  This can
    be a problem if a heating is being controlled.  
     No work around
    Is there any watch dog for this issue?

    Howdy Olaje,
    I think I've found a solution for your first question.  Take a look at this Discussion Forum and see if it does the trick.  However, I need a bit more information about your second question.  I'm curious about the specifics of how LabVIEW "locks up".  Is this a permanent crash or does it just freeze for a few minutes while control is transfered to another process?  Also, what is the context of the lock up?  Thanks for answering these follow up questions, I look forward to the response!
    Sincerely,
    Chris G in AE

  • How to show additional column in the Query searchby field selection window?

    Hi Experts,
    I have a simple query as below:
    select * from ocrd where cardcode between '[%0]' and '[%1]'
    Now, it is evident that the searchby field is the cardcode, so when I click on the browse button, all cardcodes will be displayed for me to choose on a separate selection window. Now, on this separate selection window, can I also show an additional column "customer name"?? This is because I cannot really identify every customer code, and need to depend on customer name instead.
    Thanks!
    Warmest Regards,
    Chinho
    note: please dont ask me to use the below query instead, that is not what I want to achieve.
    select * from ocrd where cardname between '[%0]' and '[%1]'

    Hi!
    It's not possible i belive. You can use Filter Option instead on Selection Parameter.

  • How to create additional column in CM21, CM25

    Hi,
    my task is to add additional column into the orders grid of cm25. I found that the user exit CYPP0005 could be used for that. Can anyone share an example of implementing EXIT_SAPLCYPP02_001?
    Best regards, Pavel.

    Hi Pavel,
    To Implement user-exit, follow the steps
    1. Go to CMOD transaction code
    2. Give Project as ZPRJ_001 and click on Create button
    3. Give some description what for the exit .
    4. Click on Enhancement assignments give your Enhancement and and press Enter.
    5. Now click on Components button. You can see the function module EXIT_SAPLCYPP02_001.
    6. Double click on EXIT_SAPLCYPP02_001 function module.
    7. In the Source code you will see one include that is zxcy1u07. Double clik on zxcy1u07. After that you will see some message. Just press ENTER button. No need on message . just press ENTER .
    8. It asks you to create Include ZXCY1U07. Click on YES and proceed to write code.Once you code save and Activate function module. And come back Project by pressing back button. and finally activate the project.
    9. Go to Transaction code or program where this Use exit has been called. Execute and check whether expected result is coming or not.
    10. Try to put break points in the source code of function module EXIT_SAPLCYPP02_001.
    I hope that you will get . Let me know if you have any problem in implementing.
    Thanks
    Venkat.O

  • Issues With How Images Output in Explorer

    I have a site at http://www.greatergoodhart.com and in Explorer 8, the photos are duplicating at the top and thus covering up the text. Does anyone else have any issues with iWeb08 sites and Explorer 8? Please help. Thanks!

    Hi Mark
    ...but the thing that really bugs me is that this a workaround
    for functionality that is supposed to work.
    I agree completely. Unfortunately, last time I checked,
    Captivate was software. And well, you know. Sometimes things don't
    work expected with software so we find workarounds to overcome what
    fails.
    At this point the best course of action is to use the
    workaround since the other method is failing. Then be certain to
    report the issue to Adobe via their official preferred channel.
    That is the Wish Form.
    Click
    here to view the WishForm/Bug Reporting Form
    Cheers... Rick

  • How to get the Column names of output that is displaying in Sql Developer(Oracle 11g).

    Hi,
        I am using OCCI to interact with DB through code, which means I am writing a vc++ file to interact with Data Base and execute the Stored Procedure which I am calling from the C++ Code. And  also displaying the output of the Stored Procedures to the Front End. I am succeeded in this, but now I should be able to display  the Column names of the output to Front End. Can any one help me on this.
    Example:
    Sno  |   Sname
    ------- |-------------
    1          ABC
    2          DEF
    I am getting (1,ABC) and (2,DEF) as the output of the Stored Procedure but I need the Column names also to display. How to get them.
    Thanks in Advance..:)

    Look at Re: exporting csv via pl/sql - select statement?
    It has an example how to extract the column name from a cursor. You have to check, whether you can use DBMS_SQL.DESCRIBE_COLUMNS
    Your procedure might need another out parameter, that returns the column names , e.g. as comma separated list or as varray.

  • EJB Issue with return empty children in join fetch query

    I'm a newbie and still trying to learn all of the facets of EJB 3.0 (and other backend capabilities) however could not find this issue anywhere resolved.
    I have a recursive table which has a 0,1-n relationship with itself. In this case, I want to query for all objects and fetch the resulting children.
    To do this I have written the following query:
    select o from Node o inner join fetch o.childrenNodeList order by o.nodeorder
    If my database has the following entries:
    Parent
    Child
    Grandchild
    The above query will get all 3 and allow me to access the list of children through getChildrenNodeList, however, for Grandchild this returns "An attempt was made to traverse a relationship using indirection that had a null Session...." for Parent and Child however it works like it should and gets the fetched rows.
    Is there a way for me to either:
    1. Modify the query so that the getChildrenNodeList will return a 0 sized array (so I can test for no children)
    2. Modify the getter such that I can check that the parent really has no children and not some issue with the query
    Thanks for any help,
    Kris

    fixed

  • Plethora of issues with my NEW computer. Apple won't help

    I bought my brand new Apple MacBook Pro in August of 2011. Paying so much for a product manufactured by such a large and notable company, one would expect to get a piece of machinery that was worth the amount of money that I spent.
    WRONG.
    Since I bought the computer, I have had NOTHING but problems with it.
    As of right now I have brought my computer in multiple times to the Apple Store (none of which are even remotely close to my location), I believe around 8 times, and the people at the Apple Store have been nothing but unhelpful and rude to me.
    When I opened the computer, there was a "Ghost Image" that the AppleStore FIXED but failed to resolve any other issues. Since then the computer has caused nothing but problems and my dealings with the Apple Store have cost me a lot of time, money and patience.
    At about the fourth visit, one would think that the staff would actually do something about the problems I was experiencing instead of running checks and telling me there was nothing wrong and that there was nothing they could do.
    Is there a way to circumvent the Apple Store and go to someone who can actually take responsibility for a faulty product sold to an extrememly unhappy customer?
    All I want is a functioning computer that I can use.
    Thanks.

    knb12 wrote:
    Perhaps.
    Although after having brought my computer into the store 8 times where they are supposedly experts at resolving issues and receiving no help, you think that writing the problems online will do a better job at solving the issues?
    Doubtful.
    Very, Extremely, Doubtful if you don't post the problems.
    Not sure how long you have been using Mac computers but if you are switching from PC to Mac Apple clearly lies about how they are easier to use. Could this be mostly user errors or unfamiliarity with the Mac OS.
    Some of the problems may be solved with a Clean install of the OS, Yes even Mac's need that from time to time (even if some old Mac fanboys say it isn't ever needed) just like Windows PCs.
    So why not give posting the problems a shot. You have Nothing to lose.

  • Issue with using formatted date value column in order by clause...

    Hi,
    1) Through a function I am listing all the months in a year.
    like JAN-2007, FEB-2007,MAR-2007......
    2) i am comparing these values against a date value column in a table.
    And if there are no values in a particular period it will return a null value (simply to say, i am using an outer join)
    3) The issue.....
    When join both the queries then the order of the dates is not mainted .....
    My requirement is......
    Jan-2007 = 3
    Feb-2007 = 5
    Mar-2007 = null
    etc.....
    should be acheived.
    But I end up in the alphabetical order of the months....
    like
    Apr-2007 = 5
    Aug-2007 = 10
    etc.....
    Can anybody let me know how can i acheive my resultant output to be ordered by the date and not by character.
    When I use the date column in the order by I run into an error....
    saying....
    ORA-01858: a non-numeric character was found where a numeric was expected
    Its a kind of urgent...
    Any help is appreciated....
    KK

    When I use a outer join as follows....
    "and upper(to_char(a.task_planned_start_date,'mon-rrrr')) = d.period_name(+)"
    All the null periods are ending at the bottom.It's standard behavoiur.
    Seems, you need to sort by a.task_planned_start_date.
    Look below:
    SQL> select e.ename, ec.ename from emp e, emp_copy ec
      2  where e.empno = ec.empno(+);
    ENAME      ENAME
    SMITH      SMITH
    ALLEN
    WARD       WARD
    JONES
    MARTIN     MARTIN
    BLAKE
    CLARK      CLARK
    SCOTT
    KING       KING
    TURNER
    ADAMS      ADAMS
    JAMES
    FORD       FORD
    MILLER
    14 rows selected.
    SQL> select e.ename, ec.ename from emp e, emp_copy ec
      2  where e.empno = ec.empno(+)
      3  order by ec.ename
      4  /
    ENAME      ENAME
    ADAMS      ADAMS
    CLARK      CLARK
    FORD       FORD
    KING       KING
    MARTIN     MARTIN
    SMITH      SMITH
    WARD       WARD
    JAMES
    TURNER
    ALLEN
    MILLER
    BLAKE
    JONES
    SCOTT
    14 rows selected.
    SQL> select e.ename, ec.ename from emp e, emp_copy ec
      2  where e.empno = ec.empno(+)
      3  order by e.ename
      4  /
    ENAME      ENAME
    ADAMS      ADAMS
    ALLEN
    BLAKE
    CLARK      CLARK
    FORD       FORD
    JAMES
    JONES
    KING       KING
    MARTIN     MARTIN
    MILLER
    SCOTT
    SMITH      SMITH
    TURNER
    WARD       WARD
    14 rows selected.Rgds.

  • Issue with How Do I Run an Executable in the Background ?

    Hi,
    I am trying to run a LabVIEw executable in the background, but none of the methods described in the discussion forum and on ni.com seems to be working. I am using LV 2011 on a Win 7 64-bit machine in case this matters.
    I tried the method described in "How Do I Run an Executable in the Background as a Start-Up Application?" (http://digital.ni.com/public.nsf/websearch/4A8B626​B55B96C248625796000569FA9?opendocument&Submitted&&​... but I still see a fragment of a window at the bottom near the start-button (Exhibit 1). Exhibit 2 shows that it only consists of the title bar. (I have customized the window appearance as described, and added the two items
    HideRootWindow=True
    UseTaskBar=FALSE
    to the *.ini file.)
    I also tried disabling all the other items in the Customize Window Appearance menu with the same result.
    Then I tried the method described in "Running a LabVIEW Executable as a Background Process" (http://digital.ni.com/public.nsf/allkb/EFEAE56A94A​007D586256EF3006E258B) adding the FP.Open method to the VI and setting the state to hidden. I got the same result (Exhibit 1).
    Is there anything I need to do in addition or different for my windows version? I appreciate your help. Thank you.
    Solved!
    Go to Solution.
    Attachments:
    LabVIEW Executable.zip ‏4058 KB

    (I have customized the window appearance as described, and added the two items
    HideRootWindow=True
    UseTaskBar=FALSE
    to the *.ini file.)
    No you did not
    They need to go in the exe's ini so the exe sees them
    Jeff

  • Syncing issues with a new computer, while old computer is dead

    Ok, So when I first purchased the iPod Nano 3rd generation, I still lived at my parents and set everything up through their computer. I bought music, and imported music to it from CD's on this computer and everything synced correctly and nicely.
    Now, I have sinced moved out and have a new computer which I have authorized, but cannot import any of the music I imported from my CD's a few years back. On top of it, I have purchased music from my new computer, but cannot sync it directly to my iPod to actually listen too for whatever reason. The final issue is that my parent's computer is completely dead, so I cannot even go on that one to deauthorize.
    Is there any way that I can get the music I have purchased recently to transfer over to my iPod? And, is there a way I can get the music I copied from old CD's into my new library on the new computer?

    Try this:
    Error: Activation Server Unavailable | CS2, Acrobat 7, Audition 3
    Just be aware that CS2 is very old software and will NOT work on current versions of either Macintosh or Windows computers. For example, it's incompatible with Mavericks on a Mac and Windows 8.

  • Issue with how Mail displays sender and recipient names in message list

    Hi everyone!
    I've been looking for a solution but had no luck so far.
    Here's the issue:
    In Mail, the sender email address or the recipient name would sometimes be displayed twice between chevrons.
    For example, sometimes in my sent folder, in the "To" column, the recipient name is displayed twice like this <[email protected]> <[email protected]> whereas it used to be displayed once and without chevrons. This happened since i have reinstalled Snow Leopard (clean install).
    Hope someone can help.
    Thanks!

    Henry,
    Please post this question on the weblogic.developer.interest.integration
    newsgroup.
    Regards,
    Raj Alagumalai
    Backline Workshop Support
    "Henry Mugasha" <[email protected]> wrote in message
    news:[email protected]..
    Hi,
    I am using a Task Control Factory to create Task Control Instances in aloop
    and then
    create tasks and assign them to a predefined group. I have an event choice
    for two events
    waiting for the onTaskCompleted and onTaskAborted event call backs.
    I have two such operations (of task creation) in the same loop. For
    simplicity I have used two separate task factory controls for each of the
    tasks (because I even had worse problems using a single control factoryfor
    both tasks in the same loop).
    When I instantiate the process, through work list I am able to claim,start
    and complete the first task. When I try the same procedure (claim, startand
    complete) on the second task, the the event choice for the corresponding
    task receives 2 event call backs. First it receives the onTaskCompleted as
    expected, but then it also received another call back of the same typewhich
    displays the error on the server log as:
    <Sep 24, 2003 9:43:56 AM EDT> <Warning> <WLW> <000000> <on process
    completion, 1 undelivered messages to
    'sampleRequestTaskFactoryCtrl_onTaskCompleted'>
    <Sep 24, 2003 9:43:56 AM EDT> <Warning> <WLW> <000000> <ejbLoad:
    Conversation 1064411008439:null not found>
    <Sep 24, 2003 9:43:56 AM EDT> <Warning> <WLW> <000000> <A message wasunable
    to be delivered from a WLW Message Queue. Attempting to deliver the
    onAsyncFailure event>
    <Sep 24, 2003 9:43:56 AM EDT> <Warning> <WLW> <000000> <ejbLoad:
    Conversation 1064411008439:null not found>
    Does anybody know why two events are fired for the same work list action?
    Thanks in advance.
    Henry M

  • How to insert additional column header using dataTable

    Hi everyone, I am using MyFaces 1.1.3, tomahawk 1.1.3, tomahawk-sandbox 1.1.5
    I have to add one column header "Proficiency" as in image [http://www.nabble.com/file/p17206601/screenshot.jpg]
    This is JSF code without "Proficiency":
    <t:dataTable id="data" value="#{commonBean.tableList}" styleClass="standardTable" headerClass="table_header" rowClasses="table_row1, table_row2" columnClasses="standardTable_Checkbox_Column,standard_text,standardTable_Checkbox_Column,standardTable_Checkbox_Column" var="value" preserveSort="true" rows="10" width="100%" border="0" sortColumn="#{commonBean.sortColumn}" sortAscending="#{commonBean.ascending}" cellpadding="2" cellspacing="1" rowIndexVar="tableRowIndex">
         <h:column>
              <f:facet name="header">
                        <h:panelGrid styleClass="table_header2">
                                  <h:outputText value="#{msg['select']}" />
                        </h:panelGrid>
              </f:facet>
              <h:selectBooleanCheckbox id="select" value="#{value.select}" />
         </h:column>
         <h:column>
              <f:facet name="header">
                        <t:commandSortHeader columnName="languageSkill" arrow="true" styleClass="table_header">
                                  <h:outputText value="#{msg['language.skill']}" />
                        </t:commandSortHeader>
              </f:facet>
              <h:commandLink action="#{commonBean.editAction}" actionListener="#{commonBean.editActionListener}">
                        <h:outputText value="#{value.languageSkill}" />
              </h:commandLink>
              <f:param id="object" value="#{value}" />
         </h:column>
         <h:column>
              <f:facet name="header">
                        <h:outputText value="#{msg['spoken']}" />
              </f:facet>
              <h:outputText value="#{value.spokenDescription}" styleClass="standardText"/>
         </h:column>
         <h:column>
              <f:facet name="header">
                        <h:outputText value="#{msg['written']}" />
              </f:facet>
              <h:outputText value="#{value.writtenDescription}" styleClass="standardText"/>
         </h:column>
    </t:dataTable>How to do ?
    Thanks for your help
    Edited by: nvduc82 on May 13, 2008 12:09 PM
    Edited by: nvduc82 on May 13, 2008 8:46 PM

    I see 2 possibilities:
    1. Merge two last columns. And then use panelGrid inside the cells.
    2. Use JSTL and tag forEach. I found it much easy-to-use.

Maybe you are looking for

  • I try to sync music to my iphone5

    I try to sync music to my iphone5 after I back up my phone (my old iphone5 was cracked then I change the new one and back up) It's said sync but nothing show on my iphone5 music but when I check on ituned in section on this phone, they had a song but

  • Split message ...

    Hi I have one outbound message and i need to split it. The result must be N messages. The outbound file contains N vendors and i have to creat as many IDOCs as vendors have in the XML outbound file. How must i set the occurrencies ? Can anybody send

  • How can I tell my current Weblogic server version and Service pack

    Hello, I was wondering how can I tell what my current weblogic server version is and what service pack it is at. Thanks.

  • Contact Service Queue Activity Report (by CSQ) Report SQL example

    I've been tasked to recreate the Contact Service Queue Activity Report (by CSQ) Report, with SQL in SQL Server 2008 RS, Can someone give me an example or actual sql for this report? I've tried to folllow the hints about joining in the documentation,

  • Report Designer - Layout height and width

    Hi Experts, Is there an option to adjust the report designer layout height and width? I am able to adjust the individual row and column height. I have a report designed in report designer which will have only 5 rows. when I execute this web template