Help on cross tab query

Hi all
I need an help
SELECT * FROM TABLE_A
ID SCHEDULED MARK
1 01/18/2011 T01
2 01/18/2011 T02
3 01/18/2011 T03
4 01/19/2011 T04
5 01/20/2011 T05 I want Results like below for folllowing query
SELECT SCHEDULED,MARK FROM TABLE_A
WHERE SCHEDULED BETWEEN TO_CHAR(SYSDATE,'MM/DD/YYYY') AND TO_CHAR(SYSDATE +1,'MM/DD/YYYY')
1/18/2010 1/19/2011
T01           T04
T02
T03
CREATE TABLE  "TABLE_A"
   (     "ID" NUMBER,
     "SCHEDULED" DATE,
     "MARK" VARCHAR2(50)
insert into table_a values(1, '01/18/2011', 'T01');
insert into table_a values( 2, ' 01/18/2011', 'T02');
insert into table_a values( 3, ' 01/18/2011', 'T03');
insert into table_a values( 4, ' 01/19/2011', 'T04');
commit;Thanks for your help

user1849 wrote:
Hi all
I need an help
SELECT * FROM TABLE_A
ID SCHEDULED MARK
1 01/18/2011 T01
2 01/18/2011 T02
3 01/18/2011 T03
4 01/19/2011 T04
5 01/20/2011 T05 I want Results like below for folllowing query
SELECT SCHEDULED,MARK FROM TABLE_A
WHERE SCHEDULED BETWEEN TO_CHAR(SYSDATE,'MM/DD/YYYY') AND TO_CHAR(SYSDATE +1,'MM/DD/YYYY')
1/18/2010 1/19/2011
T01           T04
T02
T03
CREATE TABLE  "TABLE_A"
(     "ID" NUMBER,
     "SCHEDULED" DATE,
     "MARK" VARCHAR2(50)
insert into table_a values(1, '01/18/2011', 'T01');
insert into table_a values( 2, ' 01/18/2011', 'T02');
insert into table_a values( 3, ' 01/18/2011', 'T03');
insert into table_a values( 4, ' 01/19/2011', 'T04');
commit;Thanks for your helphttp://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:766825833740

Similar Messages

  • Cross Tab Query - Help

    Dear users,
    I have a query as below:
    select a$acct$company company,
    a$period_name "Period Name",
    a$acct$location location,
    a$acct$prime_sub "Prime Sub",
    sum (balance) balance
    from apps_rpt.us_gl_balances
    where a$acct$prime_sub between '300001' and '313099'
    and a$period_name = 'DEC-01'
    and a$acct$company in ('5110')
    group by a$period_name, a$acct$location, a$acct$company, a$acct$prime_sub
    order by a$acct$prime_sub;
    Sample output of the above query is:
    COMPANY     Period Name LOCATION     Prime Sub     BALANCE
    5110     DEC-01         50008     300001              0.00
    5110     DEC-01         52424     300001              0.00
    5110     DEC-01         52513     300001              0.00
    5110     DEC-01         50008     300008              201315.00
    5110     DEC-01         50095     300008              10403.17
    5110     DEC-01         50107     300008              0.00
    5110     DEC-01         50108     300008              -1099236.04
    5110     DEC-01         50180     300008              0.00
    5110     DEC-01         51628     300008              -6396.02
    5110     DEC-01         51734     300008              -5896.51
    5110     DEC-01         51735     300008              -8525.78
    5110     DEC-01         52423     300008              -7268.64
    5110     DEC-01         52424     300008              -6945.65
    5110     DEC-01         52428     300008              -7845.70
    5110     DEC-01         52513     300008              -11309.44
    5110     DEC-01         52514     300008              -10272.08
    5110     DEC-01         52515     300008              -3861.72
    5110     DEC-01         52516     300008              -6685.85I need to write a cross tab query whose output should be some thing as below:
                         300001          300008
    50008                  0             201315.00
    52424                  0            -6945.65
    52513                  0            -11309.44
    50095                  0            10403.17 
    50107                  0            0
    50108                  0            -1099236.04
    50180                  0            0
    51628                   0           -6396.02
    51734                  0           -5896.51
    51735                  0           -8525.78
    52423                  0           -7268.64
    52428                  0           -7845.70
    52514                  0           -10272.08
    52515                  0           -3861.72
    52516                  0           -6685.85from the above cross tab results 300001 and 300008 are Prime Sub and the amount shown is Balance. The columns to the left side is Location. Company and Period Name remain the same for all the rows.
    It would great if some one can assist me in writing a cross tab query to display results as shown above.
    Thanks
    Sandeep

    Frank,
    Thanks for your reply. I Tried your method of Dynamic Pivot, but its not working.
    My dynamic_pivot_subscript.sql script is :
    SELECT DISTINCT
           ',     MAX(DECODE(PRIME_SUB,'|| PRIME_SUB||','  AS txt1,
           'BALANCE,0))  AS '||prime_sub AS txt2
    FROM
    SELECT  a$acct$location         AS LOCATION
    ,       a$acct$prime_sub        AS PRIME_SUB
    ,       SUM(BALANCE)            AS BALANCE
    FROM    apps_rpt.us_gl_balances
    WHERE   a$acct$prime_sub        BETWEEN '300001' AND '313099'
    AND     a$period_name           = 'DEC-01'
    AND     a$acct$company          IN ('5110')
    GROUP BY a$acct$location,a$acct$prime_sub
    );Sql Plus session is as follows :
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    select LOCATION
    @@dynamic_pivot_subscript
    from
            SELECT  a$acct$location         AS LOCATION
            ,       a$acct$prime_sub        AS PRIME_SUB
            ,       SUM(BALANCE)            AS BALANCE
            FROM    apps_rpt.us_gl_balances
            WHERE   a$acct$prime_sub        BETWEEN '300001' AND '313099'
            AND     a$period_name           = 'DEC-01'
            AND     a$acct$company          IN ('5110')
            GROUP BY a$acct$location,a$acct$prime_sub
    GROUP BY LOCATION
    SPOOL     OFFWhen i use sql plus session then its giving me the following error:
    @@dynamic_pivot_subscript
    ERROR at line 2:
    ORA-02019: connection description for remote database not found
    (1) The version of Oracle (and any other relevant software) you're using
    Ans :
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - 64bit Production
    I either use Toad or Sql Navigator

  • Cross tab query dynamically.

    Hi,
    i want to do crosstab in my query. but the data was not static its dynamic.
    CREATE TABLE ABTEST
      SEC_ID      NUMBER,
      MONYEAR     VARCHAR2(10 BYTE),
      NUM         NUMBER
    SET DEFINE OFF;
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200802', 13);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200803', 25);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200804', 26);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200805', 13);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200806', 10);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200807', 11);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200808', 5);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200809', 14);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200810', 17);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200811', 12);
    Insert into ABTEST
    WHERE
       (SEC_ID, MONYEAR, NUM)
    Values
       (91, '200812', 12);
    COMMIT;
    Currently it looks like below.
    SEC_ID     MONYEAR     NUM
    91     200802     13
    91     200803     25
    91     200804     26
    91     200805     13
    91     200806     10
    91     200807     11
    91     200808     5
    91     200809     14
    91     200810     17
    91     200811     12
    91     200812     12
    I want to display the data like below.
    sec_id 200802 ........200812
    91      13                12is there any can we do that by sql query or procedure. The dates are not limited its dynamic.
    Please help meout.
    Thanks & Regards,
    Venkat.

    Hi,
    The number of columns has to be hard-coded.
    If you don't know the number of columns until run-time, then you have to use dynamic SQL where, at run-time, you figure out how many columns are needed and write that many columns.
    See the script below for one way of doing that in SQL*Plus.
    How to Pivot a Table with a Dynamic Number of Columns
    This works in any version of Oracle
    The "SELECT ... PIVOT" feature introduced in Oracle 11
    is much better for producing XML output.
    Say you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    Case 0 "Basic Pivot" shows how you might hard-code three
    job types, which is exactly what you DON'T want to do.
    Case 1 "Dynamic Pivot" shows how get the right results
    dynamically, using SQL*Plus. 
    (This can be easily adapted to PL/SQL or other tools.)
    PROMPT     ==========  0. Basic Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    PROMPT     ==========  1. Dynamic Pivot  ==========
    --     *****  Start of dynamic_pivot.sql  *****
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    SPOOL     OFF
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    SPOOL     OFF
    --     *****  End of dynamic_pivot.sql  *****
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    Before creating the sub-script, turn off SQL*Plus features that are
    designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Turn these features on again before running the main query.
    */

  • How to produce dynamic cross-tab query result on this data ?

    Hi gurus,
    I have sales (simplified) sales data as below :
    create table sales_summ (area_code varchar2(3), sales_amt number, product varchar2(10) ) ;
    insert into sales_summ values ('A01', 100, 'P01');
    insert into sales_summ values ('A02', 200, 'P01');
    insert into sales_summ values ('B01', 300, 'P02');
    insert into sales_summ values ('A01', 400, 'P02');
    insert into sales_summ values ('A02', 500, 'P01');
    insert into sales_summ values ('A03', 600, 'P01');
    insert into sales_summ values ('A01', 700, 'P02');
    insert into sales_summ values ('A02', 800, 'P02');
    insert into sales_summ values ('A03', 900, 'P01');
    And I want to produce a cross-tab sales summary like below :
    Product A01 A02 A03 B01
    P01     100          700     1500          0
    P02     1100          800     0          300
    How is the query ?
    Thank you for your help,
    xtanto

    Search this forum for "pivot". Plenty of examples.
    Regards,
    Rob.

  • Help in Cross Tab!!!

    Hi All,
    I have a samll issue when creating a cross tab report with the format like this:
    Year (Group By Year)
    Quarter (repeats for every Year)
    Actual Budget Short
    customer name Quarter amounts
    TOTAL TOTAL AMOUNTS
    I have been able to create a cross tab report with only year...i am having difficulties putting in the quarters....
    any help is much appreciated.
    I can pass the rtf template created for the yearly data.
    Thanks,
    Madhavan G V

    Hi Vetsrini,
    No offence taken. I appreciate all the help i can get from this forum.
    Anyways, please find the the xml & code generated.
    XML:
    ====
    <ROWSET>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2005</YEAR>
    <QUARTER>Q1</QUARTER>
    <SALES>1000</SALES>
    </RESULTS>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2005</YEAR>
    <QUARTER>Q2</QUARTER>
    <SALES>2000</SALES>
    </RESULTS>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2004</YEAR>
    <QUARTER>Q1</QUARTER>
    <SALES>3000</SALES>
    </RESULTS>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2004</YEAR>
    <QUARTER>Q2</QUARTER>
    <SALES>3000</SALES>
    </RESULTS>
    </ROWSET>
    Code:
    ====
    <?variable:c297;xdoxslt:create_groups($_XDOCTX, RESULTS/node()[local-name()='YEAR' or local-name()='QUARTER'], 'YEAR;QUARTER', 'v')?><?horizontal-break-table:1?>
    <?for-each@cell:$c297?>
    <?for-each@cell:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?end for-each?><?end for-each?>
    <?for-each@column:$c297?>
    <?.?>
    <?for-each@column:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?.?>
    <?end for-each?><?end for-each?>
    <?for-each-group:RESULTS;./INDUSTRY?><?variable@incontext:G1;current-group()?>
    <?INDUSTRY?>
    <?for-each@cell:$c297?>
    <?sum ($G1[(./YEAR=current())]/SALES)?>
    <?for-each@cell:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?sum ($G1[(QUARTER=current())]/SALES)?> -- Problematic part. [i get the total of quarters rather than total of quarter on a year basis)
    <?end for-each?><?end for-each?>
    <?sum ($G1/SALES)?>
    <?end for-each-group?>
    <?variable@incontext:T;.//RESULTS?>
    <?for-each@cell:$c297?>
    <?for-each@cell:$c297?>
    <?for-each@cell:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?sum ($T[(./QUARTER=current())]/SALES)?>
    <?end for-each?><?end for-each?>
    <?sum ($T/SALES)?>
    Thanks,

  • Help with Cross-tab

    Hello everyone...
    Here is some quick background info on my project:
    1) I am attempting to write a Crystal Report (version 10) to automatically capture crime statistics for a previous time period based on a current time period entered into the Crystal Report parameter. The current date range to automatically be captured is the previous seven weeks. For example, if a user enters the date range of June 15, 2008 - August 2, 2008, the Crystal Report will automatically gather data for the two date ranges of April 27, 2008 - June 14, 2008 (the previous date range) and June 15, 2008 - August 2, 2008 (the current date range). The purpose of this is to automatically gather crime statistics for two equal date ranges to compare crime rates.
    2) I have been able to successfully construct a formula to gather the previous date range.
    3) I have constructed a cross-tab but I am having difficulties formatting the cross-tab to display data as I desire.
    With the background of my project now described I will move into the main problem I am experiencing. I am able to display the data for all the necessary weeks in the cross-tab; using the same date range above I am able to show data for the fourteen weeks of April 27, 2008 - August 2, 2008. However, I wish to have a single cross-tab display the grand totals for just the previous date range while having weekly totals and a grand total for the current date range.
    Using the same date ranges above as an example, the date range of April 27, 2008 - June 14, 2008 will show just the grand totals for all seven weeks of that period. Conversely, I would like to have the date range of June 15, 2008 - August 2, 2008 show weekly totals as well as grand totals for all seven weeks of that period.
    I would like to keep all this data in a single cross-tab due to having to put the data in another crime analysis report.
    Any help you can provide is most appreciated...let me know if I can provide further info. Just so you know I am a bit of a beginner when it comes to Crystal Reports.

    Hello, you might try this:
    1) Create a formula field in your details section with this:
    Whileprintingrecords;
    If (table.date >= "start date of your pre-date range" and
    table.date <= "end date of your pre-date range") then 'Pre-Date'
    else
    if (table.date >= "your 1st week start" and table.date <= "your 1st week end") then 'Week 1'
    else (if table.date >= "your 2nd week start" and table.date <= "your 2nd week end") then 'Week 2'
    else .... for the 7 weeks you want a separate column.
    2) create the cross-tab and put the formula field as the column.
    3) I believe if you right-click on the total field to the far right and "Format Field" you can use the "Display String" option to delete the sum of the previous week's from the CurrentFieldValue and use the TOTEXT() function to display it. This will only display the sum of your current 7 weeks.
    You may want to go change the "Group Options" for the column to Sort in "Specified Order" and create named groups for each of your column headings. I can explain how you would do this if you need it.

  • Help in cross tabs.

    I have a cross tab defined.
    can we show levels hierarchy in cross tabs?
    I have a hierarchy described. I have a cross tab such a way that,
    In th description on cross tab:
    If value at Level4 = 'computers' this table gives us the all sublevels under level 4 i.e.level 5
    But, even level 5 has a sublevel as Level6.
    I need to dsiplay even level 6 in the outcome.
    Its this way:
    This is my cross tab:
    http://img651.imageshack.us/img651/9179/76869600.jpg
    and the code in box C: <?crosstab:c547;"//SQL_ROW[level4='computers']";"level5";"sum_date{,o=a,t=t}";"price";"sum"?>
    This is my current output:
    http://img64.imageshack.us/img64/3011/89739442.jpg
    But I need this as outcome: how do I achieve this? Please help me :
    http://img834.imageshack.us/img834/84/27269357.jpg

    I am not clear of where to put the condition.
    can anyone help me please.
    This is my Cross tab:
    http://img163.imageshack.us/img163/9575/78212975.jpg
    This is my current out put:
    http://img411.imageshack.us/img411/7033/55191078.jpg
    But I need this Out put:
    http://img834.imageshack.us/img834/84/27269357.jpg

  • Cross tab query

    I have a question about a correlation table and getting the results whether it is there or not. I've done this in SQL Server's product but haven't had success transferring it to ORACLE. Here is the situation:
    I have a table of visitors, a table of visitor attributes and a table correlating the visitor to the attributes. The visitor doesn't need to have all of the attributes. In SQL Server I use a left outer join and join on the visitor attribute value (the correlation table) one time for each attribute in the visitor attribute table. The result should be a query that returns a recordset of all visitors with all attributes as the columns with NULL where there is no attribute value and (obviously) a value where there is one. Any help would be greatly appreciated. (Please CC responses to [email protected]).
    Here is the query that I use in SQL server:
    SELECT
    V.id id,
    V.firstvisit firstvisit,
    V.lastvisit lastvisit,
    V.visitcount visitcount,
    VAV_PHON.ATTRIBUTEVALUE Phone,
    VAV_STAT.ATTRIBUTEVALUE State,
    VAV_CITY.ATTRIBUTEVALUE City,
    VAV_ADDR.ATTRIBUTEVALUE Address,
    VAV_LAST.ATTRIBUTEVALUE Last_Name,
    VAV_FIRS.ATTRIBUTEVALUE First_Name
    FROM WT_TEST3.DBO.TBL_VISITOR V
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_PHON ON
    (VAV_PHON.VISITOR_ID = V.ID AND VAV_PHON.ATTRIBUTE_ID = 12)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_STAT ON
    (VAV_STAT.VISITOR_ID = V.ID AND VAV_STAT.ATTRIBUTE_ID = 11)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_CITY ON
    (VAV_CITY.VISITOR_ID = V.ID AND VAV_CITY.ATTRIBUTE_ID = 10)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_ADDR ON
    (VAV_ADDR.VISITOR_ID = V.ID AND VAV_ADDR.ATTRIBUTE_ID = 9)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_LAST ON
    (VAV_LAST.VISITOR_ID = V.ID AND VAV_LAST.ATTRIBUTE_ID = 8)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_FIRS ON
    (VAV_FIRS.VISITOR_ID = V.ID AND VAV_FIRS.ATTRIBUTE_ID = 7)
    null

    Hi David,
    the syntax in Oracle is:
    SELECT
    V.id id,
    V.firstvisit firstvisit,
    V.lastvisit lastvisit,
    V.visitcount visitcount,
    VAV_PHON.ATTRIBUTEVALUE Phone,
    VAV_STAT.ATTRIBUTEVALUE State,
    VAV_CITY.ATTRIBUTEVALUE City,
    VAV_ADDR.ATTRIBUTEVALUE Address,
    VAV_LAST.ATTRIBUTEVALUE Last_Name,
    VAV_FIRS.ATTRIBUTEVALUE First_Name
    FROM dbo.tbl_visitor v ,
    dbo.TBL_VISITORATRVAL VAV_PHON,
    dbo.TBL_VISITORATRVAL VAV_STAT,
    dbo.TBL_VISITORATRVAL VAV_CITY,
    dbo.TBL_VISITORATRVAL VAV_ADDR,
    dbo.TBL_VISITORATRVAL VAV_LAST,
    dbo.TBL_VISITORATRVAL VAV_FIRS
    WHERE vav_phon.visitor_id (+)= v.id
    AND vav_phon.attribute_id (+)= 12
    AND vav_stat.visitor_id (+)= v.id
    AND vav_stat.attribute_id (+)= 11
    AND vav_city.visitor_id (+)= v.id
    AND vav_city.attribute_id (+)= 10
    AND vav_addr.visitor_id (+)= v.id
    AND vav_addr.attribute_id (+)= 9
    AND vav_last.visitor_id (+)= v.id
    AND vav_last.attribute_id (+)= 8
    AND vav_firs.visitor_id (+)= v.id
    AND vav_firs.attribute_id (+)= 11The outer join operator is (+).
    Bye Max
    null

  • SQL cross tab query

    how do you do the equivilent in a webi report?
    I dont think case statements are supported
    e.g.
    Code:
    SELECT
        SUM(CASE WHEN purchase_date BETWEEN '2004-08-01' and   '2004-08-31' THEN amount ELSE 0 END) As m2004_08,
        SUM(CASE WHEN purchase_date BETWEEN '2004-09-01' and   '2004-09-30'  THEN amount ELSE 0 END) As m2004_09,
        SUM(CASE WHEN purchase_date BETWEEN '2004-10-01' and   '2004-10-31' THEN amount ELSE 0 END) As m2004_10
    FROM purchases

    your split logic sounds like a great idea Dave thanks
    I am trying to produce this statement:
    SUM(case when mks_clienttype ='C' and mks_reason4fail in ("",'pri record found') then clients end) as Client_email
    variable     clientTypeFlag
    code     =If([Mks Clienttype] = "C") Then 1 Else 0
    variable     reason4failFlag1
    code     =If([Mks Reason4fail(trim)] = "pri record found" Or [Mks Reason4fail(trim)] = "") Then 1 Else 0
    variable     clientEmail
    code              ?
    how to actually get the sum of both clientTypeFlag and reason4failFlag1? I am trying to figure it out with no luck I have tried this:
    variable: ClientEmail1
    code: =Sum([clientTypeFlag]) Where ([clientTypeFlag] = 1)
    variable: ClientEmail2
    code: =Sum([clientTypeFlag]) Where ([reason4failFlag1] = 1)
    variable: clientEmail
    code: =[ClientEmail1] + [ClientEmail2]
    want the end result to look like this:
    Name  |  clientemail
    john      |           5
    bob       |           3
    jo          |           2
    Edited by: Dennis Alishah on Sep 21, 2010 5:58 AM

  • Need a pseudo cross tab query

    Not sure how to do this. I have a table with contents as
    empid
    empnm
    office
    phone
    and another table with
    empid
    workdt
    notin
    I need to display the data such as
    empid empnm office phone 1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12
    123 joe 123 x x x
    467 sam 333
    777 bill 444 x x
    The data in the employee file looks like this
    empid empnm office phone
    123 joe 123
    467 sam 333
    777 bill 444
    The data in the workdates file looks like this
    empid workdt notin
    123 1/1/12 x
    123 1/2/12
    123 1/3/12 x
    123 1/4/12 x
    123 1/5/12
    123 1/6/12
    123 1/7/12
    467 1/1/12
    467 1/2/12
    467 1/3/12
    467 1/4/12
    467 1/5/12
    467 1/6/12
    467 1/7/12
    777 1/1/12
    777 1/2/12 x
    777 1/3/12
    777 1/4/12
    777 1/5/12 x
    777 1/6/12
    777 1/7/12

    Hi,
    There are more different options but I show two below:
    with empdef as
    select 123 empid, 'Joe' empnm,  '123' office, cast(null as varchar2(10)) phone from dual union all
    select 467,       'Sam',        '333',        null from dual union all
    select 777,       'Bill',       '444',        null from dual
    ,workdata as
    select 123 empid, to_date('01-JAN-12', 'dd-mon-yy') workdt,  'X' notin from dual union all
    select 123, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('03-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('04-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('02-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('05-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('07-JAN-12', 'dd-mon-yy'),null from dual
    select
      e.empid
      ,e.empnm
      ,e.office
      ,e.phone
      ,max(case when w.workdt = to_date('01-01-2012', 'dd-mm-yyyy') then notin else null end) "1/1/12"
      ,max(case when w.workdt = to_date('02-01-2012', 'dd-mm-yyyy') then notin else null end) "1/2/12"
      ,max(case when w.workdt = to_date('03-01-2012', 'dd-mm-yyyy') then notin else null end) "1/3/12"
      ,max(case when w.workdt = to_date('04-01-2012', 'dd-mm-yyyy') then notin else null end) "1/4/12"
      ,max(case when w.workdt = to_date('05-01-2012', 'dd-mm-yyyy') then notin else null end) "1/5/12"
      ,max(case when w.workdt = to_date('06-01-2012', 'dd-mm-yyyy') then notin else null end) "1/6/12"
      ,max(case when w.workdt = to_date('07-01-2012', 'dd-mm-yyyy') then notin else null end) "1/7/12"
    from
      empdef        e     join
      workdata     w     on (e.empid     = w.empid)
    group by
      e.empid
      ,e.empnm
      ,e.office
      ,e.phone
    order by
      e.empid
    EMPID EMPNM OFFICE PHONE      1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12
      123 Joe   123               X             X      X                          
      467 Sam   333                                                               
      777 Bill  444                      X                    X                    or with the pivot clause:
    with empdef as
    select 123 empid, 'Joe' empnm,  '123' office,  cast(null as varchar2(10)) phone from dual union all
    select 467,       'Sam',        '333',        null from dual union all
    select 777,       'Bill',       '444',        null from dual
    ,workdata as
    select 123 empid, to_date('01-JAN-12', 'dd-mon-yy') workdt,  'X' notin from dual union all
    select 123, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('03-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('04-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('02-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('05-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('07-JAN-12', 'dd-mon-yy'),null from dual
    select
    from
      empdef        e     join
      workdata      w     using (empid)
    pivot(max(notin) for workdt in (to_date( '01-01-2012', 'mm-dd-yyyy') as "1/1/12"
                                    ,to_date( '01-02-2012', 'mm-dd-yyyy') as "1/2/12"
                                    ,to_date( '01-03-2012', 'mm-dd-yyyy') as "1/3/12"
                                    ,to_date( '01-04-2012', 'mm-dd-yyyy') as "1/4/12"
                                    ,to_date( '01-05-2012', 'mm-dd-yyyy') as "1/5/12"
                                    ,to_date( '01-06-2012', 'mm-dd-yyyy') as "1/6/12"
                                    ,to_date( '01-07-2012', 'mm-dd-yyyy') as "1/7/12"
    EMPID EMPNM OFFICE PHONE      1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12
      467 Sam   333                                                               
      123 Joe   123               X             X      X                          
      777 Bill  444                      X                    X                    Regards,
    Peter

  • CROSS TAB PRINTING IN PDF PROBLEM

    Post Author: peachpx
    CA Forum: General
    Hi,
    My report uses a Cross Tab query with multiple lines for each value. Originally, I only get one line for Total In.  I modified Total In to include three lines Total Into Final, Total Into Initial and Total Out.  It displays fine in the report, but when I try to print from the server it opens PDF file with only one line present Total Into Final and the other two lines are cut off.  Is this a BUG in CRXII or is this can be fixed with correct formatting?
    Please help!

    Hi,
    cross tab is a diagonal report , u have to make query in such a way so that it returns the all field in row and columns way  i.e in diagonal form .
    U have to fetch total in same manner
    Rgds,
    Premraj

  • Issue with the Cross tab report

    Hi,
    Please any one can help on cross tab report in discoverer.
    When i ran report for one customer, it is revenu by month for given year but when i ran for all customers, it is displaying only for one month.
    Thank you,
    Madhu

    Hi,
    Please any one can help on cross tab report in discoverer.
    When i ran report for one customer, it is revenu by month for given year but when i ran for all customers, it is displaying only for one month.
    Thank you,
    Madhu

  • Oracle Cross Tabs

    Hi peers,
    i am really stack on how to do the following using Oracle SQL. I want to build a cross tab query where my columns are current year& next year months ( i.e 24 columns will be built)..
    any thoughts on how to do that ?
    thank you

    Hi sb92075 ,
    i got it i am trying to see how can i tweak it lit bit..
    in my case i have a cross tab query were values in my SELECT statment are different , example :
    SELECT *
    FROM
    SELECT
    PROJECTNAME,
    PROJECTID
    SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(sysdate,1),'mm-yyyy'), SALE,0)) as '01-2011'
    ,SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(sysdate,2),'mm-yyyy'), SALE,0)) as '02-2011'
    ,SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(sysdate,3),'mm-yyyy'), SALE,0)) as '03-2011'
    FROM TABLE
    what i am looking for is :
    1-
    to have (sysdate,1) replaced by the 1st month of the current year 'JAN-2011'
    same thing for (sysdate,2) replaced by the 1st month of the current year 'FEB-2011'
    and so on until the last month of the next year . In total 24 monthss
    2-
    for each select item , i need to have the column called by that month name i.e :
    SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(month1),'mm-yyyy'), SALE,0)) as 'month1'
    SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(month2),'mm-yyyy'), SALE,0)) as 'month2'
    any thoughts ?
    thanks

  • Cross-tab style queries...

    As you may have guessed, I'm new to the Oracle flavour of SQL.
    I'm trying to create a cross-tab query, do any of you guys know a good way of doing this?
    Thanks very much.

    You can do like this. Its an ex. you can extend as you need
    SELECT job,
    sum(decode(deptno,10,sal)) DEPT10,
    sum(decode(deptno,20,sal)) DEPT20,
    sum(decode(deptno,30,sal)) DEPT30,
    sum(decode(deptno,40,sal)) DEPT40
    FROM scott.emp
    GROUP BY job
    Hari

  • Cross tab in Oracle8i

    why access such a small database can provide cross tab query
    facility and not by oracle, if somebody knows the real and
    flexible method of doing this plz be informs us.I will be highly
    oblized
    thanks

    I came across this example recently on the site:
    http://www.onwe.co.za/frank/faqscrpt.htm
    I believe this is what you're looking for...
    rem -------------------------------------------------------------
    rem UPDATED VERSION
    rem Filename: matrix.sql
    rem Purpose: Example of a CROSS MATRIX report implemented
    using
    rem standard SQL.
    rem Date: 12-Feb-2000
    rem Author: Frank Naude ([email protected])
    rem
    rem Updated By Mahesh Pednekar. ([email protected])
    rem Description Removed the Main query because the sub query
    itself
    rem will full fill the requirement.
    rem -------------------------------------------------------------
    SELECT job,
    sum(decode(deptno,10,sal)) DEPT10,
    sum(decode(deptno,20,sal)) DEPT20,
    sum(decode(deptno,30,sal)) DEPT30,
    sum(decode(deptno,40,sal)) DEPT40
    FROM scott.emp
    GROUP BY job
    -- Sample output:
    -- JOB DEPT10 DEPT20 DEPT30 DEPT40
    -- ANALYST 6000
    -- CLERK 1300 1900 950
    -- MANAGER 2450 2975 2850
    -- PRESIDENT 5000
    -- SALESMAN 5600

Maybe you are looking for