Query help to get Matrix report

Hi All,
I have posted this query in Reports forum, didnt get replies, so im posting at Database general may be it could be the query problem.
Account Main Heads
Account_main_head_code, Main_head_description
01 ADMINSTRATIVE
02 OPERATIONAL
Ledger_codes account_code,account_description,accound_main_head_code
01 SALARIES 01
02 PHONES 01
03 FUEL 02
Terminal_master
Terminal_id,terminal_station_code
1 HYD
2 VJA
3 NY
4 WDC
Petty_cash_voucher voucher_date,terminal_id,currency_code,account_code,amount
30-jun-05 1 GBP 01 100
30-jun-05 2 GBP 01 200
30-jun-05 3 GBP 02 300
30-jun-05 4 GBP 03 250
Im looking for the MATRIX layout as follows :
GBP (first group)
ADMINISTRATIVE (secind group)
.................HYD.....VJA....NY ....WDC
Salaries.........100.....200.....0......0
Phones............0.......0.....300.....0
OPERATIONAL
.................HYD.....VJA....NY....WDC
Fuel..............0.......0.....0.....250
My query is like this
SELECT
P.currency_code,
T.terminal_town_code,
P.account_code,
L.account_description,
MH.account_main_head_description,
SUM(P.amount) total_amount
FROM
terminal_master T,
petty_cash_voucher_master P,
ledger_accounts L,
account_main_heads MH
WHERE
T.terminal_id = P.account_to_terminal (+)
AND
L.account_code (+) = P.account_code
AND
MH.account_main_head_code (+) = L.account_main_head_code
AND
P.voucher_date (+) > = '30-jun-05'
AND
P.voucher_date (+) < = '30-jun-05'
GROUP BY
P.currency_code,
T.terminal_town_code,
P.account_code,
L.account_description,
SH.account_main_head_description.
My current output is like this.
right now with the the existing query im getting like this
GBP (first group)
ADMINISTRATIVE (second group)
.................HYD.....VJA....NY ....WDC
Salaries.........100.....200.....0......0
Phones............0.......0.....300.....0
OPERATIONAL
.................WDC
Fuel.............250
While i need all the terminal at OPERATIONAL expenses also.

you'll need an auxiliary calender table :
SQL> drop table T_ACM ;
SQL> drop table T_LC  ;
SQL> drop table T_TM  ;
SQL> drop table T_PCV ;
SQL> drop table T_CAL ;
SQL>
SQL> create table T_ACM (acm_code varchar2(2) not null, text varchar2(20) not null) ;
SQL> create unique index T_ACM_PK on T_ACM (acm_code) ;
SQL> insert into T_ACM values ('01','ADMINISTRATIVE') ;
SQL> insert into T_ACM values ('02','OPERATIONAL'   ) ;
SQL>
SQL>
SQL> create table T_LC     (lc_code varchar2(2) not null, text varchar2(20) not null, acm_code varchar2(2) ) ;
SQL> create unique index T_LC_PK on T_LC (lc_code) ;
SQL> insert into T_LC values ('01' , 'SALARIES' , '01') ;
SQL> insert into T_LC values ('02' , 'PHONES'     , '01') ;
SQL> insert into T_LC values ('03' , 'FUEL'     , '02') ;
SQL>
SQL>
SQL> create table T_TM (tm_id     number         not null, tm_code varchar2(3) ) ;
SQL> create unique index T_TM_PK on T_TM (tm_id) ;
SQL> insert into T_TM values (1, 'HYD' ) ;
SQL> insert into T_TM values (2, 'VJA' ) ;
SQL> insert into T_TM values (3, 'NY'  ) ;
SQL> insert into T_TM values (4, 'WDC' ) ;
SQL>
SQL>
SQL> create table T_PCV (v_date date not null, tm_id  varchar2(3) , cur_code varchar2(3), lc_code varchar2(2), amount number ) ;
SQL> insert into T_PCV values (sysdate , 1, 'GBP', '01' , 100) ;
SQL> insert into T_PCV values (sysdate , 2, 'GBP', '01' , 200) ;
SQL> insert into T_PCV values (sysdate , 3, 'GBP', '02' , 300) ;
SQL> insert into T_PCV values (sysdate , 4, 'GBP', '03' , 150) ;
SQL>
SQL> insert into T_PCV values (sysdate-1 , 1, 'GBP', '01' , 101) ;
SQL> insert into T_PCV values (sysdate-1 , 2, 'GBP', '01' , 201) ;
SQL> insert into T_PCV values (sysdate-1 , 3, 'GBP', '02' , 301) ;
SQL> insert into T_PCV values (sysdate-1 , 4, 'GBP', '03' , 151) ;
SQL>
SQL> insert into T_PCV values (sysdate-2 , 1, 'GBP', '01' , 102) ;
SQL> insert into T_PCV values (sysdate-2 , 2, 'GBP', '01' , 202) ;
SQL> insert into T_PCV values (sysdate-2 , 3, 'GBP', '02' , 302) ;
SQL> insert into T_PCV values (sysdate-2 , 4, 'GBP', '03' , 152) ;
SQL>
SQL> create table T_CAL (DAY date not null, WEEK number, MONTH number, YEAR number) ;
SQL> create unique index T_CAL_PK on  T_CAL (DAY);
SQL>
SQL> DECLARE
  2    l_year number ;
  3  BEGIN
  4 
  5    l_year := 2005 ;
  6 
  7    FOR i in 1..365 LOOP
  8        insert into T_CAL (DAY,YEAR)
  9              select to_date(to_char(i) || ' ' || to_char(l_year) , 'DDD YYYY')
10                 ,l_year
11             from dual
12        ;
13    END LOOP ;
14 
15    commit ;
16 
17       update T_CAL
18          set WEEK  = to_number(to_char(T_CAL.DAY,'WW'))
19             ,MONTH = to_number(to_char(T_CAL.DAY,'MM'))
20       ;
21    commit ;
22  END ;
23  /
SQL>
SQL>
SQL>
SQL> commit ;
SQL>
SQL>
SQL>
SQL>
SQL> create or replace
  2   view v_test_2 as
  3  select
  4           E.DAY
  5          ,E.acm_text
  6          ,E.lc_text
  7          ,E.tm_code
  8          ,nvl(sum(F.amount),0) amount
  9    from
10            (select A.text acm_text, B.lc_code, B.text lc_text, C.tm_id, C.tm_code , D.DAY
11            from
12                 T_ACM    A
13                ,T_LC     B
14                ,T_TM     C
15                ,T_CAL    D
16            where
17                 A.acm_code = B.acm_code
18            ) E
19           ,(select trunc(v_date) DAY, tm_id, lc_code, sum(amount) amount
20            from t_pcv
21              group by trunc(v_date), tm_id, lc_code
22            ) F
23   where
24            E.lc_code = F.lc_code (+)
25       and  E.tm_id   = F.tm_id   (+)
26       and  E.DAY     = F.DAY        (+)
27   group by
28           E.DAY
29          ,E.acm_text
30          ,E.lc_text
31          ,E.tm_code
32  ;
SQL> select * from v_test_2
  2   where DAY >= to_date('01.07.2005','dd.mm.yyyy')
  3       and DAY <= to_date('02.07.2005','dd.mm.yyyy')
  4  ;
DAY      ACM_TEXT             LC_TEXT              TM_     AMOUNT              
01.07.05 ADMINISTRATIVE       PHONES               HYD          0              
01.07.05 ADMINISTRATIVE       PHONES               NY         301              
01.07.05 ADMINISTRATIVE       PHONES               VJA          0              
01.07.05 ADMINISTRATIVE       PHONES               WDC          0              
01.07.05 ADMINISTRATIVE       SALARIES             HYD        101              
01.07.05 ADMINISTRATIVE       SALARIES             NY           0              
01.07.05 ADMINISTRATIVE       SALARIES             VJA        201              
01.07.05 ADMINISTRATIVE       SALARIES             WDC          0              
01.07.05 OPERATIONAL          FUEL                 HYD          0              
01.07.05 OPERATIONAL          FUEL                 NY           0              
01.07.05 OPERATIONAL          FUEL                 VJA          0              
01.07.05 OPERATIONAL          FUEL                 WDC        151              
02.07.05 ADMINISTRATIVE       PHONES               HYD          0              
02.07.05 ADMINISTRATIVE       PHONES               NY         300              
02.07.05 ADMINISTRATIVE       PHONES               VJA          0              
02.07.05 ADMINISTRATIVE       PHONES               WDC          0              
02.07.05 ADMINISTRATIVE       SALARIES             HYD        100              
02.07.05 ADMINISTRATIVE       SALARIES             NY           0              
02.07.05 ADMINISTRATIVE       SALARIES             VJA        200              
02.07.05 ADMINISTRATIVE       SALARIES             WDC          0              
02.07.05 OPERATIONAL          FUEL                 HYD          0              
02.07.05 OPERATIONAL          FUEL                 NY           0              
02.07.05 OPERATIONAL          FUEL                 VJA          0              
02.07.05 OPERATIONAL          FUEL                 WDC        150              
SQL>
SQL> select
  2           B.MONTH
  3          ,A.acm_text
  4          ,A.lc_text
  5          ,A.tm_code
  6          ,sum(amount) amount
  7    from
  8          V_TEST_2  A
  9         ,T_CAL     B
10   where B.DAY   = A.DAY (+)
11       and B.MONTH = 7
12   group by
13           B.MONTH
14          ,A.acm_text
15          ,A.lc_text
16          ,A.tm_code
17  ;
     MONTH ACM_TEXT             LC_TEXT              TM_     AMOUNT            
         7 ADMINISTRATIVE       PHONES               HYD          0            
         7 ADMINISTRATIVE       PHONES               NY         601            
         7 ADMINISTRATIVE       PHONES               VJA          0            
         7 ADMINISTRATIVE       PHONES               WDC          0            
         7 ADMINISTRATIVE       SALARIES             HYD        201            
         7 ADMINISTRATIVE       SALARIES             NY           0            
         7 ADMINISTRATIVE       SALARIES             VJA        401            
         7 ADMINISTRATIVE       SALARIES             WDC          0            
         7 OPERATIONAL          FUEL                 HYD          0            
         7 OPERATIONAL          FUEL                 NY           0            
         7 OPERATIONAL          FUEL                 VJA          0            
         7 OPERATIONAL          FUEL                 WDC        301            
SQL>
SQL>
SQL> select
  2           B.MONTH
  3          ,A.acm_text
  4          ,A.lc_text
  5          ,A.tm_code
  6          ,sum(amount) amount
  7    from
  8          V_TEST_2  A
  9         ,T_CAL     B
10   where B.DAY   = A.DAY (+)
11       and B.MONTH = 6
12   group by
13           B.MONTH
14          ,A.acm_text
15          ,A.lc_text
16          ,A.tm_code
17  ;
     MONTH ACM_TEXT             LC_TEXT              TM_     AMOUNT            
         6 ADMINISTRATIVE       PHONES               HYD          0            
         6 ADMINISTRATIVE       PHONES               NY         302            
         6 ADMINISTRATIVE       PHONES               VJA          0            
         6 ADMINISTRATIVE       PHONES               WDC          0            
         6 ADMINISTRATIVE       SALARIES             HYD        102            
         6 ADMINISTRATIVE       SALARIES             NY           0            
         6 ADMINISTRATIVE       SALARIES             VJA        202            
         6 ADMINISTRATIVE       SALARIES             WDC          0            
         6 OPERATIONAL          FUEL                 HYD          0            
         6 OPERATIONAL          FUEL                 NY           0            
         6 OPERATIONAL          FUEL                 VJA          0            
         6 OPERATIONAL          FUEL                 WDC        152            
SQL>

Similar Messages

  • Need help in getting UM report

    Hi Champs,
    Can any one help to get the report ?
    how to run a report against Exchange UM in order to display who has recorded a custom greeting versus those that have not done anything? 
    we need to be able to report on which users have recorded their new voicemail greeting versus those who still have the default message.
    Thanks in advance.
    Regards
    Vijendhar

    have you seen this link?
    http://www.onesimplescript.com/2012/02/auditing-exchange-um-mailbox-recordings.html
    regards Holger Technical Specialist UC

  • Please help create this matrix report

    Hi,
    I'm using Reports6i.
    I want to create a matrix report like below.
    Country            JUN2008       JUL2008
                      Teu    Feu     Teu   Feu
    INDIA             13        9       1     10  .....
    .With the query i've written, i get the data like
    Country      Dt       Cnt       Typ
    IN     JUN2008           9             Feu
    IN     JUN2008           13     Teu
    IN     JUN2008           10             Feu
    IN     JUN2008           1     TeuPlease Help
    Edited by: Divya on Jun 21, 2011 5:55 AM

    Which tool are you using to create the report Divya?
    You may use PIVOT to create the matrix like report.
    For Ex;
    SELECT *
    FROM (SELECT product_code, quantity
    FROM pivot_test)
    PIVOT (SUM(quantity) AS sum_quantity FOR (product_code) IN ('A' AS a, 'B' AS b, 'C' AS c));
    A_SUM_QUANTITY B_SUM_QUANTITY C_SUM_QUANTITY
    210 90 160

  • Need help in getting a report from SAP!

    Hi,
    I'm in charge of a manufacturing operation. I need your help to find a report of OPEN PLANNED ORDERS. I'm using spreadsheets to control the production but I need to get this information from SAP directly. NO MORE EXCEL!!!
    Can somebody help?
    JB

    you may not be able to avoid the excel part, but I guess it is worth a try. Take a look at using a query tool to look at the table name PLAF, you could additionally join this table to MAKT for the full material description and perhaps VBAK if you need sales order related header data which may be tied to your planned orders

  • Query help,  Percentages / ratio to reports / nests

    Hi
    I have a query that returns data like this
    D_NO POINTS COUNT_POINTS ID_COUNT
    4002 L_T_69 12 282
    4219 L_T_69 1 151
    4228 L_T_69 18 193
    4229 L_T_69 7 181
    4230 L_T_69 0 197
    I need to also output a column that works out a percentage of count_points and Id_count. e.g 12/282 * 100 = 4.2
    I had a try with ratio to reports function but no joy for me. I think i need to add in
    another nested select or something but what i was trying wasnt working.
    Can anyone help.
    here is the query so far
    SELECT D_NO,
    GROUPS.POINTS,
    DECODE(GROUPS.POINTS, 'L_T_69' , L_T_69) AS COUNT_POINTS,
    ID_COUNT
    FROM
         (SELECT D_NO,
         Count (CASE WHEN VERBAL <= 69 THEN 1
              END) AS L_T_69,
         COUNT(ID_NUMBER) AS ID_COUNT
         FROM TBL_1
         WHERE VERBAL IS NOT NULL
         group by D_NO)
    TBL_1,
    ( SELECT 'L_T_69' POINTS FROM DUAL )GROUPS
    thank you

    Not sure if this is what you're looking for but it may give you some clues:
    select object_type
          ,has_a_c
          ,type_total
          ,round(100 * (has_a_c / type_total),2) ratio
    from
       select object_type
             ,sum (case when instr(object_name,'C') <> 0 then 1
                        else 0
                   end) has_a_c
             ,count(*) type_total
       from   all_objects
       group by object_type
    OBJECT_TYPE          HAS_A_C   TYPE_TOTAL   RATIO
    CONSUMER GROUP             1            2      50
    EVALUATION CONTEXT         1            1     100
    FUNCTION                  50          113   44.25
    INDEX                      7           20      35
    LIBRARY                    0            2       0
    OPERATOR                   1            2      50
    PACKAGE                  500         1158   43.18
    PACKAGE BODY             487         1126   43.25
    PROCEDURE                 54           86   62.79
    SEQUENCE                  62          116   53.45
    SYNONYM                 1060         2298   46.13
    TABLE                    365          721   50.62
    TABLE PARTITION           15           15     100
    TYPE                     104          272   38.24
    VIEW                     834         1896   43.99
    15 rows selected.

  • Query help to Get day wise count

    I have a table: Table_Sample with two columns:
    Date_Time_Field - Timestamp;
    Request_Type - Number;
    The insert statement for the table is as follows:
    -- INSERTING into TABLE_SAMPLE1
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('01-JUL-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),1);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('01-JUL-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),2);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('12-JUL-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),2);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('01-AUG-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),7);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('21-SEP-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),2);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('03-OCT-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),1);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('13-OCT-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),1);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('04-NOV-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),7);
    I want to get the count of request_Type on each day..In this table some dates are missing, but i want to fill the count of request_Type on those days as 0.
    i.e., expected out put is
    Date          Request_Type              Count(Request_Type)
    01-JUL-07         1                             1
    01-JUL-07         2                             1
    01-JUL-07         7                             0
    02-JUL-07         1                             0
    02-JUL-07         2                             0
    02-JUL-07         7                             0
    03-JUL-07         1                             0
    03-JUL-07         2                             0
    03-JUL-07         7                             0
    11-JUL-07         1                             0
    11-JUL-07         2                             1
    11-JUL-07         7                             0
    :How can i form the query for this

    Using Data Densification for Reporting (available on 10g and above):
    SQL> with Request_Types AS (
      2    select distinct request_type from TABLE_SAMPLE1
      3  ),
      4  Calendar as (
      5    select date '2007-07-01' + level - 1 as date_time
      6    from dual
      7    connect by level <= 13
      8  )
      9  select c.date_time, rt.request_type, sum(case when ts.rowid is null then 0 else 1 end) as cnt
    10  from Request_Types rt
    11    join Calendar c on 1=1
    12    left outer join Table_Sample1 ts partition by (date_time_field, request_type)
    13    on ts.request_type = rt.request_type
    14       and trunc(ts.date_time_field) = c.date_time
    15  group by c.date_time, rt.request_type
    16  order by c.date_time, rt.request_type
    17  ;
    DATE_TIME  REQUEST_TYPE        CNT
    01.07.2007            1          1
    01.07.2007            2          1
    01.07.2007            7          0
    02.07.2007            1          0
    02.07.2007            2          0
    02.07.2007            7          0
    03.07.2007            1          0
    03.07.2007            2          0
    03.07.2007            7          0
    04.07.2007            1          0
    04.07.2007            2          0
    04.07.2007            7          0
    05.07.2007            1          0
    05.07.2007            2          0
    05.07.2007            7          0
    06.07.2007            1          0
    06.07.2007            2          0
    06.07.2007            7          0
    07.07.2007            1          0
    07.07.2007            2          0
    07.07.2007            7          0
    08.07.2007            1          0
    08.07.2007            2          0
    08.07.2007            7          0
    09.07.2007            1          0
    09.07.2007            2          0
    09.07.2007            7          0
    10.07.2007            1          0
    10.07.2007            2          0
    10.07.2007            7          0
    11.07.2007            1          0
    11.07.2007            2          0
    11.07.2007            7          0
    12.07.2007            1          0
    12.07.2007            2          1
    12.07.2007            7          0
    13.07.2007            1          0
    13.07.2007            2          0
    13.07.2007            7          0
    39 rows selected.Regards,
    Dima

  • Help to get milestones report for all sales documents

    Dear Friends,
      Could you please tell me the standard reports for milestone detail i.e combining FPLA and FPLT...
      Apprecaite your valuable and quick response.
    Thanks
    Siva

    Try transaction VA05. In that choose "Open Orders" along with other selection criteria.
    If you want the Open sales order qty in output and its not displayed, do the following.
    Sales -> System modification -> create new fields ( without condition technique) -> New fields for lists.
    You can change V05TZZMO and structure VBMTVZ from there or use SE38 / SE11.
    For both you'll need an object registration in OSS.
    Hope this helps.
    Thanks,
    Balaji

  • Help in getting matrix value

    Hi
    How do you get a value from the matrix(example: sales order matrix) when the column is not shown. For example, getting the warehouse code of the line when the column is not shown?
    I tried using datasource, but they say illegal form/reserved.
    Any suggestions?

    You can use DIAPI Recordset.DoQuery.
    Of course you must know which table, column and row stores the information you need.
    You'll need these to go forward:
    - View - System Information  (ctrl-shift-D)
    - Database Table Reference
    - SELECT * FROM XXX1
    HTH
    Juha

  • Can u please help in getting this report  "using customer exit."....

    Hi friends.
    can any body pls suggest how this report lay out could be formed.
    when you enter in selection as  0CALMONTH = Nov 2007.
    The report should give the values of a K.F (return rate), in the following manner .
    july     july-aug      july - sep       july - oct         july - nov.
    i.e it should always give the values of that K.F starting from july , then july -aug , then july-sep , july-oct and july -nov ..(it shld show  the cumulated values starting from july )
    The fiscal year  always starts from july and ends with june .
    say if you give  0calmonth  = FEB 2007, THEN THE TREPORT SHOULD FETCH TE VALUES
    july2006      july -aug      july-sep          july -oct         jul- nov       july- dec   jul - jan2007    july2006 - feb 2007
    can you plesae tell me in detail  how to this . if we have to use CUSTOMER EXIT ,pls give me the code how to do this. your answers will be suitably rewarded.

    Hi,
    Try using offset varaiable of calmonth.
    Regards
    siva

  • Query Help in Report

    Hi guys ,
    I need to make a matrix report like the following
    Description Year(2002 Full),Year(2002 Till Date),Year(2002 Till Month),Year(2003 Full),Year(2003 Till Date),Year(2003 Till Month)
    Year its easy to get in the query as the following
    select item,sum(qty)to_char(v_date,'YYYY') from table group by item v_date
    but how will i get the year to date and year till month
    item wuill be my row
    qty will be cell
    and year will be column

    If the current date is 25th oct 2004 so in above query i need as
    2002 Full Year i.e jan 2002 to dec 2002
    2002 YTD Jan 2002 - 25t oct 2002
    2002 Year To Month - jan2002 oct 2002
    2003 Full Year i.e jan 2003 to dec 2002
    2003 YTD Jan 2003 - 25t oct 2003
    2003 Year To Month - jan 2003 oct 2003
    Any help will be appreciated

  • Query to get Weekly Report

    Hello,
    I wrote a query to get weekly report, which should start from Sunday to Saturday a typical week. for example the week is 04/03/2011 to 04/09/2011 i run the query on or Job on say on anyday of the week of 04/10/2011, 04.11.2011 etc.. here is my query, but this seems to work from the sysdate to - 7 days which doesn't get the sunday to sat requirement.. can someone please help..
    select uid, psn, TO_char(date_in,'mm/dd/yyyy')
    FROM TEST
    WHERE uid like '%ST%'
    and date_in > trunc(SYSDATE) -7
    ORDER BY date_in ASC;
    Thank you.

    789287 wrote:
    Centiful,
    Thank youvery much for your help. it works now. This should work any day of this week i run will get previous week's data right? 'IW' means ISO calenadar?Yes IW in the TRUNC function means truncate the date passed to the first day of the ISO Week (Monday).
    I made this as a procedure and created a job to run on a weekly basis. once the Job runs and gets the data into text file onto the server, i have to mail the text file to the management automatically through a dbms_scheduler. How can i send an email automatically through a Scheduler? could anyone give me an example please?Instead of creating the text file you could return the data and send it directly in a mail using UTL_MAIL
    Another alternative would be to use DBMS_SCHEDULER to invoke an external executable that could send the mail for you.

  • Matrix Report Query Problem

    Dear members
    I am using reports 6 and oracle 9i. I am trying to create a matrix report in which i want to show products as rows and dates as columns. Dates should be fixed 7 days any from to dates given by user. I have used two tables prd_plan_m and product_code. I want to show plan_no and plan_qty based on product_code and date. I want to show all the products as rows whether it has plan or not and 7 days columns shows as heading weather in this there is any plan or not.
    For this reason i have made this query.
    SELECT ALL p.code,pkg_prod.get_prod_name(p.code)prod_name,pkg_prod.get_prod_qty(p.code)prod_qty,P.PLAN_ID, P.PLAN_DESC, a.dates,
    P.PLAN_QTY, P.UNIT_ID, P.REMARKS
    FROM PRD_PLAN_M P ,(select rownum - 1 + to_date('20-jul-08', 'dd-mon-rrrr') dates
    from all_objects
    where rownum < to_date('26-jul-08', 'dd-mon-rrrr') -
    to_date('20-jul-08', 'dd-mon-rrrr') + 2)a
    where P.PLAN_DATE(+) = A.DATES
    UNION
    SELECT E.P_CODE,E.PROD_NAME,E.PROD_QTY,null,null,null,null,null,null FROM PROD_CODE E
    But this query shows duplicates rows. suppose one product_code in prd_plan_m has plan_qty shows one row and the row from product_code table also show the same row which have no plan qty.
    Help me in this regard.
    I will be very thankful to you .
    thanks and regards

    Thanks for reply. But this query is also produce the same results see bellow output.
    CODE     PROD_NAME     PROD_QTY     PLAN_ID     PLAN_DESC     DATES     PLAN_QTY UNIT_ID     REMARKS
    0101     MOUNTAIN DEW     225 ML NR               
    0201     PEPSI MAX     240 ML          
    0301     PEPSI          250 ML          P0001L01 TEST PLANE-01     7/21/2008 20000 1          test
    0301     PEPSI          250 ML
    0302     MOUNTAIN DEW     250 ML          P0005L02 NEW ENTRY     7/26/2008 20000          TEST
    0302     MOUNTAIN DEW     250 ML
    Code 0301 and 0302 are repeated. But they should be shown only once. Please help me to resolve this problem.
    thanks & regards

  • Matrix Report 's Query Output is not as Toad...!!!!!!

    Hello,
    i have the following Query
    SELECT ALL
    FINANCIAL_YEAR_MONTHS.month_desc||' '|| substr( FINANCIAL_YEAR_MONTHS.month_code,4,4)  months,
    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE,
    CDE_MATERIALS.MATERIAL_DESC, CDE_MATERIALS.PARENT_MATERIAL,
    PLN_PLAN_DISTRIBUTION_WAY.EXPECTED_QUANTITY,
    PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE,
    PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE
    FROM
    PLN_PLAN_DISTRIBUTION_WAY,
    PLN_PLAN_PRODUCTS,
    CDE_MATERIALS,
    FINANCIAL_YEAR_MONTHS
    WHERE
    (PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = PLN_PLAN_PRODUCTS.MATERIAL_CODE)
    AND (    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = CDE_MATERIALS.MATERIAL_CODE   )
    AND (PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE = PLN_PLAN_PRODUCTS.GROUP_CODE)
    AND ( PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE= PLN_PLAN_PRODUCTS.FIN_YEAR_CODE )
    AND (  PLN_PLAN_DISTRIBUTION_WAY.MONTH_CODE = 
    to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2)))
    AND( to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2)) >= 7 )
    AND (PLN_PLAN_DISTRIBUTION_WAY.DISTRIBUTION_WAY = :P_DISTRIBUTION_WAY )
    AND (PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE = :P_FIN_YEAR_CODE)
    UNION ALL
    SELECT ALL
    FINANCIAL_YEAR_MONTHS.month_desc||' '|| substr( FINANCIAL_YEAR_MONTHS.month_code,4,4)  months,
    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE,
    CDE_MATERIALS.MATERIAL_DESC, CDE_MATERIALS.PARENT_MATERIAL,
    PLN_PLAN_DISTRIBUTION_WAY.EXPECTED_QUANTITY,
    PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE,
    PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE
    FROM
    PLN_PLAN_DISTRIBUTION_WAY,
    PLN_PLAN_PRODUCTS,
    CDE_MATERIALS,
    FINANCIAL_YEAR_MONTHS
    WHERE
    (PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = PLN_PLAN_PRODUCTS.MATERIAL_CODE)
    AND (    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = CDE_MATERIALS.MATERIAL_CODE   )
    AND (PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE = PLN_PLAN_PRODUCTS.GROUP_CODE)
    AND ( PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE= PLN_PLAN_PRODUCTS.FIN_YEAR_CODE )
    AND (  PLN_PLAN_DISTRIBUTION_WAY.MONTH_CODE = 
    to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2)))
    AND to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2))<= 6 
    AND (PLN_PLAN_DISTRIBUTION_WAY.DISTRIBUTION_WAY = :P_DISTRIBUTION_WAY )
    AND (PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE = :P_FIN_YEAR_CODE) the Report is a Matrix Report with Group Material_names as Rows and financial Months as Columns and the expected_Quantity as cells of that report matrix.
    Well,the query runs just fine in Toad as
    Months Material_code Material_Desc ..etc.
    July 2007 1 abc
    July 2007 2 def ...etc.
    June 2008 1 abc ..etc.
    June 2008 2 def ...etc.
    But in a report the output of months are a mess not ordered as a fin_year months..
    i tried to change the design of the report from Matrix group to Matrix got same result...
    Any Suggestions pls.
    Regards,
    Abdetu..

    This the Query with order by which doesn't return the required order..
    SELECT ALL
    FINANCIAL_YEAR_MONTHS.month_desc||' '|| substr( FINANCIAL_YEAR_MONTHS.month_code,4,4)  months,
    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE,
    CDE_MATERIALS.MATERIAL_DESC, CDE_MATERIALS.PARENT_MATERIAL,
    PLN_PLAN_DISTRIBUTION_WAY.EXPECTED_QUANTITY,
    PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE,
    PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE
    FROM
    PLN_PLAN_DISTRIBUTION_WAY,
    PLN_PLAN_PRODUCTS,
    CDE_MATERIALS,
    FINANCIAL_YEAR_MONTHS
    WHERE
    (PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = PLN_PLAN_PRODUCTS.MATERIAL_CODE)
    AND (    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = CDE_MATERIALS.MATERIAL_CODE   )
    AND (PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE = PLN_PLAN_PRODUCTS.GROUP_CODE)
    AND ( PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE= PLN_PLAN_PRODUCTS.FIN_YEAR_CODE )
    AND (  PLN_PLAN_DISTRIBUTION_WAY.MONTH_CODE = 
    to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2)))
    AND( to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2)) >= 7 )
    AND (PLN_PLAN_DISTRIBUTION_WAY.DISTRIBUTION_WAY = :P_DISTRIBUTION_WAY )
    AND (PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE = :P_FIN_YEAR_CODE)
    UNION ALL
    SELECT ALL
    FINANCIAL_YEAR_MONTHS.month_desc||' '|| substr( FINANCIAL_YEAR_MONTHS.month_code,4,4)  months,
    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE,
    CDE_MATERIALS.MATERIAL_DESC, CDE_MATERIALS.PARENT_MATERIAL,
    PLN_PLAN_DISTRIBUTION_WAY.EXPECTED_QUANTITY,
    PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE,
    PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE
    FROM
    PLN_PLAN_DISTRIBUTION_WAY,
    PLN_PLAN_PRODUCTS,
    CDE_MATERIALS,
    FINANCIAL_YEAR_MONTHS
    WHERE
    (PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = PLN_PLAN_PRODUCTS.MATERIAL_CODE)
    AND (    PLN_PLAN_DISTRIBUTION_WAY.MATERIAL_CODE = CDE_MATERIALS.MATERIAL_CODE   )
    AND (PLN_PLAN_DISTRIBUTION_WAY.GROUP_CODE = PLN_PLAN_PRODUCTS.GROUP_CODE)
    AND ( PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE= PLN_PLAN_PRODUCTS.FIN_YEAR_CODE )
    AND (  PLN_PLAN_DISTRIBUTION_WAY.MONTH_CODE = 
    to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2)))
    AND to_number(substr( FINANCIAL_YEAR_MONTHS.month_code,1,2))<= 6 
    AND (PLN_PLAN_DISTRIBUTION_WAY.DISTRIBUTION_WAY = :P_DISTRIBUTION_WAY )
    AND (PLN_PLAN_DISTRIBUTION_WAY.FIN_YEAR_CODE = :P_FIN_YEAR_CODE)
    ORDER BY months

  • Please help to get onhand stock report with last purchase and billed date warehouse and item wise

    please help to get onhand stock report with last purchase and billed date warehouse and item wise

    Hi Rajeesh Ambadi...
    Try This
    SELECT distinct T0.ITEMCODE , t1.ItemName, T0.ONHAND as 'Total Qty',  
      T1.LASTPURDAT ,t1.LastPurPrc
    FROM OITW T0 INNER JOIN OITM T1 ON T0.ITEMCODE = T1.ITEMCODE
    INNER JOIN OITB T2 ON T1.ITMSGRPCOD=T2.ITMSGRPCOD left join ibt1 t3 on t3.itemcode = t0.itemcode and t3.whscode = t0.whscode
    WHERE
    T0.ONHAND>0
    AND T0.WhsCode ='[%0]'
    Hope Helpful
    Regards
    Kennedy

  • Need help in matrix report

    <p>Dear fellows,<br>
    <br>
    I am designing a matrix report of Rooms those are vacant at certian time and
    days of week. In this time values are fixed, I have written the mention below
    query to design the report.<br>
    <b><br>
    Table Description is</b> <br>
    <br>
    <br>
    SQL> desc vac_rm<br>
    Name                            
    Null?     Type<br>
    ----------------------------------------- -------- ----------------------------<br>
    RM_NO                                           
        NOT NULL VARCHAR2(8)<br>
    DAY                                                     
    NOT NULL VARCHAR2(9)<br>
    TIME                                                    
    NOT NULL VARCHAR2(20)<br>
    VACANT                                                                  
    CHAR(1)<br>
    <br>
    <b>Query is</b> <br>
    SELECT day, time,<br>
    LTRIM(MAX(SYS_CONNECT_BY_PATH(rm_no,','))<br>
    KEEP (DENSE_RANK LAST ORDER BY curr),',') AS Room<br>
    FROM (SELECT day,time, rm_no,<br>
    ROW_NUMBER() OVER (PARTITION BY day ORDER BY rm_no) AS curr,<br>
    ROW_NUMBER() OVER (PARTITION BY day ORDER BY rm_no) -1 AS prev<br>
    FROM vac_rm <br>
    where vacant = 'Y'))<br>
    GROUP BY day, time<br>
    CONNECT BY prev = PRIOR curr AND day = PRIOR day<br>
    START WITH curr = 1<br>
    <br>
    The problem occur in this way that when I see the result It show same room no
    many time in single cell.<br>
    <br>
    For Example there is Room A1 and it is vacant on monday at <br>
    9:00 AM - 11:00 AM, then it will show<br>
    <br>
    <b>Time</b>            9:00 AM - 11:00
    AM    11:15 AM - 1:00 PM<br>
    <b>Day</b> <b><br>
    Moday</b>            
    A1, A1, A1                A1, A1, A1, A3, A2<br>
    <br>
    I am very grateful In this regard if you sort out this matter. <br>
     </p>

    For the periods, create a seperate dummy query and then use it as column group in the multi query matrix.

Maybe you are looking for