Display two columns of the sum

Hi all

I am a beginner and need help on a requirement.

I have a table.

Level of ID data
----------------------
1 TL 200
1 BT 200
1 TL 200
1 BT 300
2 TL 300
BT 2 400

I want to display:

ID Sum (BT) Sum (TL)
----------------------------------
1 500 400
2 400 300

Thank you very much.

You have to change the table and column names.
The column names that you use are reserved words of Oracle...

select pk
,      sum(case
             when lvl = 'BT'
             then descr
             else 0
          end
          )sumBT
,      sum(case
             when lvl = 'TL'
             then descr
             else 0
          end
          )sumTL
from   t
group by pk;

Output:

        PK      SUMBT      SUMTL
---------- ---------- ----------
         1        500        400
         2        400        300

2 rows selected.

Tags: Database

Similar Questions

  • Displays two values in the column with the concatenation of good

    I have a query Select col1 | ' >' || col2 from table1.

    For example: the table below has the records.

    Col1 Col2
    Orange color
    red color
    White color
    Yellow color

    Result of: existing query
    Orange > color
    Red > color
    White > color
    Yellow > color

    But I want to display two columns in the order appropriate as the below one.
    Veuileez note that all the the first character of the col2 must start the position of sampe in a row.

    Orange > > color
    Red > > > > color
    White > > > color
    Yellow > > > color

    Hello
    Knowing the value that should be completed when running...

    SQL>  with tab as
      2   (select 'Orange' Col1, 'color' Col2 from dual union all
      3   select 'red' , 'color' from dual union all
      4   select 'White' , 'color' from dual union all
      5   select 'Yellow' , 'color' from dual)
      6   Select RPAD(col1,(select max(length(col1)) +1
      7   from tab),chr(32))||chr(9) ||col2 data
      8   from tab;
    
    DATA
    --------------------------------------------------------------
    Orange  color
    red     color
    White   color
    Yellow  color
    

    Twinkle

  • I can't have multiple files open at the same time! I need to compare the content from one to the other. How to display two files at the same time?

    I can't have multiple files open at the same time! I need to compare the content from one to the other. How to display two files at the same time?

    Hi sindres79946597,

    Open Acrobat Reader DC, navigate to the Edit-> Preferences-> General-> uncheck "Open Documents in the new tab in the same window.

    Now, reboot your system, when you open multiple PDFs that all will open in a new window so that you can easily compare.

    Kind regards
    Nicos

  • ViewCriteria comparing two columns of the table to create

    Anyone know how I can create a ViewCriteria where clause that compares the two columns of the same table?

    For example if I had two columns of integers (MINSAL and MAXSAL) and wanted to see if they are equal. Normally, I would do the following SQL below.

    SELECT * EMPL
    WHERE MINSAL = MAXSAL

    Try to link any of them to an expression of groovy.

    Timo

  • Need to display more than two columns in the game now (library view)

    The current reading list (under the library, not the instant game tab menu tab a top of the player) shows only two columns, the title and duration.  I can't add more columns by selecting choose columns, or restore the columns.  I have this problem with one of the entries in the left column of the display of the library (like, songs, recently added, etc.).  Is there a way can I fix?

    It's machine running a version of Windows XP on the computer and WMP11.  I had Windows XP and media player 11 on my laptop for several years and have had this problem.  I don't know what is different between the two machines that causes this problem.

    Yes, it seems to be more at hand than just differences in operating system. However, I think I found a way to get more columns in the game now:

    1 restart WMP, start to play music and go to playback.

    2. click on the heading of column Title to sort by title.

    3. switch to another view (for example songs ) and go back to playing now. You should already see the additional columns now.

    4. to make the columns 'stick' between reboots WMP, you also needed to right click on the column header in the current playback, select Choose columns , uncheck automatically hide columns and click OK .

    Tim Baets
    http://www.BM-productions.TK

  • Help!  Calculate a percentage between two fields that the sum of columns

    Members of the forum good day!

    I'm hoping to get help with and model RTF I use to sum up the output of a query in PeopleSoft.

    I have a line with two fields of the query and a third field calculates a percentage using the query fields:
    Row1, Field1: EXPR14_14
    Row1, Field2: EXPR1_1
    Row1, Field3: <? xdofx: If EXPR1_1 <>0 and EXPR14_14 0 then (EXPR1_1 DIV EXPR14_14) <>* 100 or 0 end if? >

    I have a second row who has these fields:
    Row2, Field1: <? sum (EXPR14_14)? >
    Row2, Field2: <? sum (EXPR1_1)? >
    Row3, Field3: I need the third field to calculate the percentage of sum of two fields.

    I tried different ways to insert this calculation with no luck. It's my first time to create a rtf report and any help would be gratly appreciated.

    In advanced thank you for your help.

    Kind regards
    Raquel

    For the calculation of percentage you can use something similar to this (adjust the formula you need)

    For Row1, Field3:

    Hope that helps. If you need more help, send me the xml file and the [email protected] model

    Thank you
    Bipuser

  • Columns of the sum of different record count of joined tables

    I have a problem with a query, please help.

    I have two tables:
    create table rec_a (key_code varchar(20),
                    TOT_AMT varchar(20),
                    INV_AMT varchar(20))
    / 
     
    create table rec_B (key_code varchar(20),
                    INVOICE_AMT varchar(20),
                   PAID_AMT varchar(20))
    / 
     
    insert into REC_A values (123123,  1168182.16, 1168182.16);
    
    insert into REC_B values (123123, 205699.04,205699.04);
    insert into REC_B values (123123,130912.78,130912.78);
    insert into REC_B values (123123, 81622.87,81622.87);
    insert into REC_B values (123123, 438032.43,438032.43);
    insert into REC_B values (123123, 159936.17,159936.17);
    insert into REC_B values (123123, 151978.87,151978.87);
     
    Table 1
    KEY_CODE TOT_AMT INV_AMT
    123123 1168182.16 1168182.16


    Table 2
    KEY_CODE INVOICE_AMT PAID_AMT
    123123 205699,04 205699.04
    123123 130912,78 130912.78
    123123 81622,87 81622.87
    123123 438032,43 438032.43
    123123 159936,17 159936.17
    123123 151978,87 151978.87


    I wrote a query to sum up all the areas (tot_amt, inv_amt, invoice_Amt, paid_amt)
    SELECT B.key_code,sum(A.invoice_amt),sum(a.paid_amt),SUM(b.tot_Amt),SUM(b.inv_amt) FROM rec_a B, rec_b A WHERE A.KEY_CODE=B.KEY_CODE AND B.KEY_CODE in ('123123')
    group by B.key_code
    I got this:

    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 7009092.96 7009092.96

    But I expected this

    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 1168182.16 1168182.16


    Can someone help me out here?

    Thank you

    Published by: 1003064 on April 29, 2013 03:19

    Hello

    1003064 wrote:
    I have a problem with a query, please help.

    I have two tables:
    Table 1
    KEY_CODE TOT_AMT INV_AMT
    123123 1168182.16 1168182.16

    Table 2
    KEY_CODE INVOICE_AMT PAID_AMT
    123123 205699,04 205699.04
    123123 130912,78 130912.78...
    123123 81622,87 81622.87
    123123 438032,43 438032.43
    123123 159936,17 159936.17
    123123 151978,87 151978.87

    I wrote a query to sum up all the areas (tot_amt, inv_amt, invoice_Amt, paid_amt)

    SELECT B.key_code, sum (a.invoice_amt), sum (a.paid_amt), SUM (b.tot_Amt), SUM (b.inv_amt) FROM rec_a A, rec_b B WHERE A.KEY_CODE = B.KEY_CODE AND B.KEY_CODE in ('123123')
    B.key_code group

    I got this:
    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 7009092.96 7009092.96

    But I expected this

    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 1168182.16 1168182.16

    Thus, the last 2 columns must be exactly what is stored in table1? Then either
    b include these columns in the GROUP BY clause and not to use the SUM,
    (b) the GROUP BY on rec_a alone, separately, can't join the results to the rec_b, or
    (c) using MIN or MAX, instead of SUM. (Anyone. Since there is only one value, MIN will be the same as MAX.)

    Here is an example of (a):

    SELECT    B.key_code
    ,       sum (a.invoice_amt)     AS sum_invlice_amt
    ,       sum (a.paid_amt),     AS sum_paid_amt
    ,       b.tot_Amt
    ,       b.inv_amt
    FROM        rec_a          A
    ,        rec_b          B
    WHERE        A.KEY_CODE     = B.KEY_CODE
    AND        B.KEY_CODE      in ('123123')
    group by  B.key_code
    ,            b,tot_amt
    ,       b.inv_amt
    ;
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • Calculation on two columns in the pivot table

    Hi all

    I have a vision:
    Dept. year amount
    Accounting 500 $2010
    Accounting 700 $2011
    $100 engineering 2010
    $600 engineering 2011
    and etc.


    PivotTable: (data displayed side by side)

    Dept: 2010 2011
    Accounting 500 $700 $
    Engineering 100-$600

    Is there a way of PivotTable to create the additional column, and do the math on this column? New column called 'Change' (amount of real computation of 2010 less amount of 2011 by each Department). I see the function to duplicate columns in the PivotTable. But that's it... without additional calculations.

    Thank you in advance,

    Sonya

    Pretty easy simple n...

    Your year must be in the columns area... Simply create a new collar calculated say diff with function as formula and formula of the sale as a "2011" "- 2010". This will give you the sum of diff. You can do this more flexible by making use of $1 & $2 to reference...

  • display / hide column of the table running

    Are there known issues with display / hide a column of the table at run time?

    I have a table that contains a column with a check box and another with a radio button.  If the user is allowed to select more than one row in the table (as indicated by a form variable), then I want to hide the column of radio and checkbox column.  If not, I want to show / hide the contrary.

    I show / hide the column header too.  When I preview the form, however, the data in the table appears "scoot" left and placed in the column that is hidden, so to speak.

    Here is a view of the design of the table:

    tableDesignView.jpg

    And a view of the execution of the table.  You can see the radio is hidden, but the "account number" column wants to crush in the (hidden) radio column,

    tableRunTimeView.jpg

    Here is the script, I'm very confident in this small snippet of code because the lines of account were filling wonderfully until I added the column of radio buttons and the script to show/hide.

    Put the account data in the table

    function

    setAccountData (objAccountRow, objAccountItem) //Pass in the line and data to complete line

    {

    stuff the line

    objAccountRow.accountNumber.rawValue

    = objAccountItem.accountNumber;

    objAccountRow.accountName.rawValue

    = objAccountItem.accountName;

    objAccountRow.accountBalance.rawValue

    = objAccountItem.accountBalance;

    display the check box or radio button, depending on the number of accounts they are allowed to select (as specified by the form variable)

    var searchNumAccounts = objFragment.resolveNode("searchNumAccounts").value; Variable //Form

        if (searchNumAccounts==1)

    { //show the column of radio buttons and hide the checkbox column }

    hideObject (objResultsSubform.accounts.HeaderRow.txtSelect);   <-it's exaggerated here, to hide the table for each row header column,...

    hideObject (objAccountRow.accountSelected);

    showObject (objResultsSubform.accounts.HeaderRow.txtRadioSelect);

    showObject (objAccountRow.radioSubform.radioGroup.selected);

    }

    on the other

    { //show the checkbox column and hide the column of radio }

    hideObject (objResultsSubform.accounts.HeaderRow.txtRadioSelect);

    hideObject (objAccountRow.radioSubform.radioGroup.selected);

    showObject (objResultsSubform.accounts.HeaderRow.txtSelect);

    showObject (objAccountRow.accountSelected);

    }

    }

    OK I got it. The table object implements a container to contain the fields. You hid the ok fields, but you then never reset the row in the table to have only two columns. I copied the parameter of the XML source so that I would have the exact width and then deleted the one I wanted to hide. Now everything works fine.

    See the example updated the.

    Paul

  • How to update a record, if it is a composite key (primary key is based on two columns) in the OPS? page?

    Hello

    Actually I got to know this update of a record must be made when the primary key is based on two columns.

    Previously, I used SPEL for a column. It was working fine.

    But I came to know that regardless of the folder I try to update, it was the update page is coming up with the first combination of the record.

    As if RC 131

    RC 124

    RC 125 are the records.

    If I click on update of RC 124 also, the update page is coming up with RC 131 values as it is the first.

    So I understand that the SPEL should be based on two parameters, because it is a composite key.

    How to do?

    Please let me know if you don't understand the problem.

    Thank you.

    Wow!

    I got it.

    Thank you brothers, always a hope that you could help me

  • Check the values in two columns, in the affirmative, then generate an error

    Oracle 10g version

    Hi gurus

    I'm test1 table and it contains several columns, my requirement I want to create some sort of conditions or constraints before inserting data into test1, it will check that application_id or APPLICATION_TYPE_CD contains no values in the two columns...

    I appreciate your advice. Thank you

    / / DESC test1

    APPLICATION_ID NUMBER (10)

    DATE OF APPLICATION_DT

    APPLICATION_TYPE_CD VARCHAR2 (10)

    DATE OF CREATED_DT

    Concerning

    MIT

    You need a check as a constraint:

    ALTER table test1 add constraint only_one

    check ((application_id n'est pas null et application_type_cd est null) or)

    (application_id is null and application_type_cd is not null))

    John

  • How to add two columns in the criteria (OBIEE 11 g)

    Hello

    I try to add two columns in a criterion of obiee

    * "Done - OLB processed invoices. "" Invoice amount - currency "__" made - OLB processed invoices "." " The amount of taxes AR - billing currency"

    but the problem is:-
    The first column have 500000000 and the second column contains some NULL values from the table. I think that this could be the problem when I try to add that it gives no output.
    just an empty box.

    Can someone tell me how we can add columns in this State.

    Thank you to each and every one.

    Try IFNULL (expr, value)
    for the other columns

    "Done - OLB processed invoices". " Charge the amount - currency "+ IFNULL (" made - OLB processed invoices "". ")" AR tax - currency billing", 0)

    Published by: Srini VIEREN on March 20, 2013 10:02

  • Index on two columns becomes the index of function?

    Hello, I create a unique index with two columns, a number (9) and a date.

    It becomes an index of feature based with the number column and a column sys hidden (date).

    When I do queries that use this index the autotrace tells me it does things like this:

    sys_nc00001$ > SYS_OP_DESCEND (datevalue)
    sys_nc00001$ IS NOT NULL

    How is he did not have a normal index?

    Use of ESCR does this.

    Of http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm

    Oracle database processes Index descending as if they were focused on the index function.

  • MSN displays two icons in the taskbar

    Hello and sorry if my English is not so good. Upgrading to windows 7 yesterday and had just this one problem for now. When I connect to my msn he opens two windows in the taskbar. We have the msn as before and the other just my msn pic. As a result, I can't minimize it by clicking on the task bar, when I click on the window already open. And of course I constantly get confused which icon to click to view my msn. How can I make the second window disappear?

    Gr_thalia,

    To get Windows Live Messenger to run as it did in previous versions of Windows, try to open in Compatibility Mode:
    1. Make sure that Windows Live Messenger is completely closed
    2. Go to the Windows Live Messenger executable by clicking Start > computer > Local disk (c) > Program Files > Windows Live > Messenger
    3. Find msnmsgr, right-click and choose Properties
    4. Click on the compatibility tab
    5. In Compatibility Mode, check the run this program in compatibility mode for: , then select Windows Vista (Service Pack 2) from the drop-down
    6. Click OK to close the Properties window
    Hope that helps!

    Cody C
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Dynamic display of columns in the pivot query

    I have a table called STUDENT_SCORE. I need to display the avarage score/month for 2 years and the monthly score until today "month.

    Then assume that it is April 2009. The report will look like

    Roll_id 2007avg 2008avg Jan09-Mar09 Feb 09
    101 80.9 70.9 89.7 90.9 56.8
    102 70.9 23.9 87.2 90.0 76.8


    I tried a bit, but can't fix the monthly score display dynamically.


    DDL/DML is as below


    create the table STUDENT_SCORE
    (number of roll_id,
    date of mth_id,
    The partition number);


    insert into STUDENT_SCORE values
    (101, to_date (January 1, 2006 ', ' dd/mm/yyyy'), 67.5);
    insert into STUDENT_SCORE values
    (101, to_date (February 1, 2006 ', ' dd/mm/yyyy'), 77.5);
    insert into STUDENT_SCORE values
    (101, to_date (March 1, 2006 ', ' dd/mm/yyyy'), 87.5).
    insert into STUDENT_SCORE values
    (101, to_date (April 1, 2006 ', ' dd/mm/yyyy'), 27.5);
    insert into STUDENT_SCORE values
    (101, to_date (May 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (June 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (July 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (August 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (September 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (October 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (November 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (December 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (January 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (February 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (March 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (April 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (May 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (June 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (July 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (August 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (September 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (October 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (November 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (December 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (1 January 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (February 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (March 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (April 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (May 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (June 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (July 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (August 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (September 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (October 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (November 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (December 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (101, to_date (January 1, 2009 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (January 1, 2006 ', ' dd/mm/yyyy'), 67.5);
    insert into STUDENT_SCORE values
    (102, to_date (February 1, 2006 ', ' dd/mm/yyyy'), 77.5);
    insert into STUDENT_SCORE values
    (102, to_date (March 1, 2006 ', ' dd/mm/yyyy'), 87.5).
    insert into STUDENT_SCORE values
    (102, to_date (April 1, 2006 ', ' dd/mm/yyyy'), 27.5);
    insert into STUDENT_SCORE values
    (102, to_date (May 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (June 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (July 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (August 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (September 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (October 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (November 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (December 1, 2006 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (January 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (February 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (March 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (April 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (May 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (June 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (July 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (August 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (September 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (October 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (November 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (December 1, 2007 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (1 January 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (February 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (March 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (April 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (May 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (June 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (July 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (August 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (September 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (October 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (November 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (December 1, 2008 ', ' dd/mm/yyyy'), 57.5);
    insert into STUDENT_SCORE values
    (102, to_date (January 1, 2009 ', ' dd/mm/yyyy'), 57.5);

    Hello

    The script below produces what you want (as far as I can tell, without your desired results).

    Student_score_smry subquery Gets the year and monthly averages of student_score.
    It is completely static: it always produces 11 monthly columns (from January to November) and the names of columns hardcoded (m01 through m11).
    For dynamic column names you need, I used SQL * COLUMN more orders.
    To get the variable number of monthly columns you need, SELECT from the main query clause uses a script under (dynamic_month.sql) to only show the correct number (which can be 0).

    The student_score_wk_smry of subquery retrieves the weekly averages of the student_score_wk.
    He, too, is completely static: it always produces 6 weekly columns with names hardcoded (w1 through w6).

    There are four preliminary motions, that write two scripts under:
    Prelimiary C1, C2 and C3 queries write orders of COLUMN for annual, monthly and weekly columns in dynamic_columns.sql
    Preliminary motion M written between 0 and 11 items in SELECT-clause in sub-script dynamic_month.sql

    The main script is:

    SET     FEEDBACK     OFF
    SET     LINESIZE     200
    SET     PAGESIZE     0
    SET     VERIFY          OFF
    
    SPOOL     dynamic_column.sql
    
    -- Preliminary query C1: Columns for last 2 years
    SELECT     'COLUMN     y'
         ||     LEVEL
         ||     '     HEADING     "'
         ||     TO_CHAR     ( ADD_MONTHS     ( &target_month
                             , 12 * (-3 + LEVEL)
                             )
                   , 'YYYY'
                   )
         ||     'avg"'
    FROM     dual
    CONNECT BY     LEVEL <= 2
    ;
    
    -- Preliminary query C2: 11 prior months in this year
    SELECT     'COLUMN     m'
         ||     TO_CHAR     (LEVEL, 'fm00')
         ||     '     HEADING     "'
         ||     TO_CHAR     ( ADD_MONTHS     ( TRUNC (&target_month, 'YYYY')
                             , LEVEL - 1
                             )
                   , 'MonYY'
                   )
         ||     '"'
    FROM     dual
    CONNECT BY     LEVEL <= 11
    ;
    
    -- Preliminary query C3: 6 weeks before target_month
    WITH     got_w_num     AS
    (
         SELECT     SUBSTR (week_desc, 1, 6)     AS mon_dd
         ,     ROW_NUMBER () OVER
                   (     ORDER BY     week_id     DESC
                   )     AS w_num
         FROM     week
         WHERE     TO_DATE (week_desc, 'Mon DD, YYYY')     < &target_month
    )
    SELECT     'COLUMN     w'
         ||     TO_CHAR (7 - w_num)
         ||     '     HEADING     "Week of '
         ||     mon_dd
         ||     '"'
    FROM     got_w_num
    WHERE     w_num     <= 6
    ORDER BY     w_num     DESC
    ;
    
    SPOOL     OFF
    
    -- Preliminary Query M: 0-11 months (in SELECT clause)
    SPOOL     dynamic_month.sql
    
    SELECT     ',     m'
         ||     TO_CHAR (LEVEL, 'fm00')
    FROM     dual
    WHERE     MONTHS_BETWEEN (&target_month, TRUNC (&target_month, 'YYYY')) >= 1
    CONNECT BY     LEVEL <= MONTHS_BETWEEN (&target_month, TRUNC (&target_month, 'YYYY'))
    ;
    
    SPOOL     OFF
    
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     LINESIZE     80
    SET     PAGESIZE     50
    
    -- COLUMN Commands
    @dynamic_column.sql
    
    -- Main Query
    WITH     student_score_smry     AS
    (
         SELECT     roll_id
         ,     AVG (CASE WHEN TRUNC (mth_id, 'YYYY') = TRUNC (ADD_MONTHS (&target_month, -24), 'YYYY')     THEN score END)     AS y1
         ,     AVG (CASE WHEN TRUNC (mth_id, 'YYYY') = TRUNC (ADD_MONTHS (&target_month, -12), 'YYYY')     THEN score END)     AS y2
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') =             TRUNC (&target_month, 'YYYY')      THEN score END)     AS m01
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  1) THEN score END)     AS m02
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  2) THEN score END)     AS m03
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  3) THEN score END)     AS m04
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  4) THEN score END)     AS m05
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  5) THEN score END)     AS m06
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  6) THEN score END)     AS m07
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  7) THEN score END)     AS m08
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  8) THEN score END)     AS m09
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'),  9) THEN score END)     AS m10
         ,     AVG (CASE WHEN TRUNC (mth_id, 'MM') = ADD_MONTHS (TRUNC (&target_month, 'YYYY'), 10) THEN score END)     AS m11
         FROM     student_score
         GROUP BY     roll_id
    )
    ,     got_w_num     AS
    (
         SELECT     week_id
         ,     ROW_NUMBER () OVER
                   (     ORDER BY     week_id     DESC
                   )     AS w_num
         FROM     week
         WHERE     TO_DATE (week_desc, 'Mon DD, YYYY')     < &target_month
    )
    ,     student_score_wk_smry     AS
    (
         SELECT     roll_id
         ,     AVG (CASE WHEN W_NUM = 6 THEN score END)     AS w1
         ,     AVG (CASE WHEN W_NUM = 5 THEN score END)     AS w2
         ,     AVG (CASE WHEN W_NUM = 4 THEN score END)     AS w3
         ,     AVG (CASE WHEN W_NUM = 3 THEN score END)     AS w4
         ,     AVG (CASE WHEN W_NUM = 2 THEN score END)     AS w5
         ,     AVG (CASE WHEN W_NUM = 1 THEN score END)     AS w6
         FROM     student_score_wk     s
         JOIN     got_w_num          w     ON     s.wk_id     = w.week_id
         WHERE     w_num     <= 6
         GROUP BY     roll_id
    )
    SELECT     NVL (ss.roll_id, ssw.roll_id)     AS roll_id
    ,     y1, y2
    @dynamic_month.sql
    ,     w1, w2, w3, w4, w5, w6
    FROM          student_score_smry     ss
    FULL OUTER JOIN     student_score_wk_smry     ssw     ON     ss.roll_id     = ssw.roll_id
    ORDER BY     roll_id
    ;
    

    Sub-script dynamic_column.sql might look like this:

    COLUMN     y1     HEADING     "2007avg"
    COLUMN     y2     HEADING     "2008avg"
    COLUMN     m01     HEADING     "Jan09"
    COLUMN     m02     HEADING     "Feb09"
    COLUMN     m03     HEADING     "Mar09"
    COLUMN     m04     HEADING     "Apr09"
    COLUMN     m05     HEADING     "May09"
    COLUMN     m06     HEADING     "Jun09"
    COLUMN     m07     HEADING     "Jul09"
    COLUMN     m08     HEADING     "Aug09"
    COLUMN     m09     HEADING     "Sep09"
    COLUMN     m10     HEADING     "Oct09"
    COLUMN     m11     HEADING     "Nov09"
    COLUMN     w1     HEADING     "Week of Dec 21"
    COLUMN     w2     HEADING     "Week of Dec 28"
    COLUMN     w3     HEADING     "Week of Jan 04"
    COLUMN     w4     HEADING     "Week of Jan 11"
    COLUMN     w5     HEADING     "Week of Jan 18"
    COLUMN     w6     HEADING     "Week of Jan 25"
    

    Other sub-script, dynamic_month.sql, might look like this:

    ,     m01
    ,     m02
    ,     m03
    

Maybe you are looking for