Product wise count

Oracle 11.2.0.1
Windows 7
I have two tables:
1.Product_master
(prod_id, prod_name)
2.Sales_master
(billno,prd1,prd2,prd3,prd4,prd5)
Prd(n) columns says that bill's sold product ids, i.e. in one bill there can be max 5 products exists, may also be less than 5 but at least one, no repitation of id.
Now, I have a select query by which i may get the total counts of a prod id with its name, i.e. Suppose prod id 10 exists in bill no. 100,200,205 and prod id in bill no. 100,103,205 then output should be:
10 prod1 3
20 prod2 3
3 means these products has been sold 3 times/3 different bills were generated.
Kindly help me.
Thanks.

create table sales_master(billno varchar2(10),prd1 varchar2(2),prd2 varchar2(2),prd3 varchar2(2),prd4 varchar2(2),prd5 varchar2(2));
insert into sales_master values ('123456','40','25','14',null,null);
insert into sales_master values ('123457','10',null,null,null,null);
insert into sales_master values ('123458','15','03','42','18','23');
insert into sales_master values ('123459','15',null,null,null,null);
insert into sales_master values ('123460','03','10','40',null,null);
insert into sales_master values ('123461','14','42',null,null,null);
--Another Table :
create table prod_master(product_id varchar2(2),product_name varchar2(30));
insert into prod_master values ('01','COLD-II STRIPS');
insert into prod_master values ('02','IRON RINGS');
insert into prod_master values ('10','METAL RINGS');
insert into prod_master values ('03','SOLID PIPES-I');
insert into prod_master values ('14','COPPER ROD-2CM');
insert into prod_master values ('40','H.P.C.F.');
insert into prod_master values ('42','KRD-CMT');
insert into prod_master values ('25','BROON TOUGH');
insert into prod_master values ('15','ROUND CHIPS-KP');
insert into prod_master values ('23','ZERO WIRE-2P');
insert into prod_master values ('18','FLAT CHIPS-KP');
commit;
SQL> select * from sales_master;
BILLNO     PR PR PR PR PR
123456     40 25 14
123457     10
123458     15 03 42 18 23
123459     15
123460     03 10 40
123461     14 42
6 rows selected.
SQL> select * from prod_master;
PR PRODUCT_NAME
01 COLD-II STRIPS
02 IRON RINGS
10 METAL RINGS
03 SOLID PIPES-I
14 COPPER ROD-2CM
40 H.P.C.F.
42 KRD-CMT
25 BROON TOUGH
15 ROUND CHIPS-KP
23 ZERO WIRE-2P
18 FLAT CHIPS-KP
11 rows selected.Required Output : Product wise count of bills, suppose I want to get whole products count then :
SELECT       p.product_id, p.product_name
,    COUNT (DISTINCT s.billno)     AS cnt
FROM         prod_master  p
JOIN         sales_master    s  ON  p.product_id  IN ( s.prd1
                                          , s.prd2
                                          , s.prd3
                                          , s.prd4
                                          , s.prd5
GROUP BY  p.product_id, p.product_name
ORDER BY 1
PR PRODUCT_NAME    COUNT [This is only comment part please]
03 SOLID PIPES-I       2 (Because It has been sold under 2 bills i.e. 123458,123460)
10 METAL RINGS         2 (Because It has been sold under 2 bills i.e. 123457,123460)
14 COPPER ROD-2CM      2 (Because It has been sold under 2 bills i.e. 123456,123461)
15 ROUND CHIPS-KP      2 (Because It has been sold under 2 bills i.e. 123458,123459)
18 FLAT CHIPS-KP       1 (Because It has been sold under 1 bill i.e. 123458)
23 ZERO WIRE-2P        1 (Because It has been sold under 1 bill i.e. 123458)
25 BROON TOUGH         1 (Because It has been sold under 1 bill i.e. 123456)
40 H.P.C.F.            2 (Because It has been sold under 2 bills i.e. 123456,123460)
42 KRD-CMT             2 (Because It has been sold under 2 bills i.e. 123458,123461)
Which your above worked perfectly.Now, if suppose I wish to get count of only for product_id in('15,'23','42') then output should be :
PR PRODUCT_NAME    COUNT
15 ROUND CHIPS-KP      2 (Because It has been sold under 1 bills i.e. 123458,123459)
23 ZERO WIRE-2P        1 (Because It has been sold under 1 bills i.e. 123458)
42 KRD-CMT             2 (Because It has been sold under 2 bills i.e. 123458,123461)
SELECT       p.product_id, p.product_name
,    COUNT (DISTINCT s.billno)     AS cnt
FROM         prod_master  p
JOIN         sales_master    s  ON  p.product_id  IN ( s.prd1
                                          , s.prd2
                                          , s.prd3
                                          , s.prd4
                                          , s.prd5
where p.product_id in('15','42','23')
GROUP BY  p.product_id, p.product_name
ORDER BY 1
It also worked perfectly.Ok, now suppose if I says :
insert into sales_master values ('123462','22',null,null,null,null);
--i.e. product id which is is not in product master table and I says :
SELECT       p.product_id, p.product_name
,    COUNT (DISTINCT s.billno)     AS cnt
FROM         prod_master  p
full JOIN         sales_master    s  ON  p.product_id  IN ( s.prd1
                                          , s.prd2
                                          , s.prd3
                                          , s.prd4
                                          , s.prd5
GROUP BY  p.product_id, p.product_name
ORDER BY 1
PR PRODUCT_NAME                          CNT
01 COLD-II STRIPS                          0
02 IRON RINGS                              0
03 SOLID PIPES-I                           2
10 METAL RINGS                             2
14 COPPER ROD-2CM                          2
15 ROUND CHIPS-KP                          2
18 FLAT CHIPS-KP                           1
23 ZERO WIRE-2P                            1
25 BROON TOUGH                             1
40 H.P.C.F.                                2
42 KRD-CMT                                 2
PR PRODUCT_NAME                          CNT
                                           1
12 rows selected.while I need :
03 SOLID PIPES-I                           2
10 METAL RINGS                             2
14 COPPER ROD-2CM                          2
15 ROUND CHIPS-KP                          2
18 FLAT CHIPS-KP                           1
22 [New Product]                           1  <<----
23 ZERO WIRE-2P                            1
25 BROON TOUGH                             1
40 H.P.C.F.                                2
42 KRD-CMT                                 2In addition to above, I need output as below also (new requirement told by admin after posting the question, I am sorry)
Final required output (by adding new requirement after question posting)
PR PRODUCT_NAME                          CNT    BILL1      BILL2     BILL3    BILL4
03 SOLID PIPES-I                           2   123458     123460
10 METAL RINGS                             2   123457     123460
14 COPPER ROD-2CM                          2   123456     123461
15 ROUND CHIPS-KP                          2   123458     123459
18 FLAT CHIPS-KP                           1   123458    
22 [New Product]                           1   123462                                   
23 ZERO WIRE-2P                            1   123458    
25 BROON TOUGH                             1   123456     
40 H.P.C.F.                                2   123456     123460
42 KRD-CMT                                 2   123458     123461i.e. if count of product is less than 4 bills then those bill numbers should also be there, because those products are rarely sold and we wish to know who purchased those products by looking into that bill number.
I am again thankful to you for your support.
Thanks.
Edited by: user12050217 on Dec 10, 2012 8:57 PM

Similar Messages

  • Vendor wise product wise details report

    Dear all,
    please give me any standard report for vendorwise product wise details. and also  customer wise and product wise details report.

    Pls have a look on the blw link which is the std sap reports, its provided by sap.. hope it will be helpful for u.
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/erplo/sapStandardReports

  • Product wise sales report

    hi ,
    we are having sales gl accounts on domestic and export now we want to know the products wise report
    please tell me if any standard t-code

    u can find copa line item report (ke24)

  • Page Wise Count of rows

    Hi ,
    How to get page wise count of rows of the inner repeating group?
    Thanks in advance.
    --Basava.S                                                                                                                                                                                                                       

    Hi Dimant,
    I used countrows. If the dataset set contains 12 rows I am getting the o/p as shown below. I just need one row. Can please help me out.
    Thanks
    sush

  • Product wise Profitability Report

    Hello,
    Currently we are using F.01 for profitability report.
    However, the report for profitablility as available here is on Business Area wise.
    We need the same kind of report but Product wise profitability.
    Is there any standard report available for the requirement ?
    Currently we are extracting data from MB5B and KE5Z and preparing the report manually in excel.
    Many Thanks in advance.
    Regards,
    Nirav

    Hi Nirav
    If you have COPA implemented - Create a "report form" from KE34 and report from KE31 and execute from KE30
    If you dont have COPA, then what you are doing is the only solution.. At best, you can create an ABAP report to extract the data you are manually extracting as of now
    br, Ajay M

  • Product wise pending sales order

    Hello,
    From which transaction code we can find out the Product wise pending sales order list.
    thanks
    harish

    Hi,
    Kindly make use of filter options and change layout options.This might help you for report format.But ultimately the details are going to be the same I guess
    In the initial screen if you give the date range you will get the list of pending orders for that particular material and the organizational detail you give.
    Reward points if helpful.
    Regards,
    Amrish Purohit

  • COPA Product wise profitability

    Hi Sapians
    I have execute an order settlement and variance is successfully posted in COPA Value field VV002(Qty variance)
    In product wise profitability report. System shows as follows:
    Product   Qty    Sales value   Cost @ Std price  order Variance VV002
    2000001   10      10000          20,000                   2000
    I have settled suppose 100 process orders for this product. Sales made for only 10 Qty where is remaining variance.

    For your specific requirement, you need to use Actual Costing with Material Ledger. This would apply the variances to the COGS sold and the balance to the Inventory account.
    Regards
    Lalit Bhatt

  • Product wise slow moving / Non-moving

    Hi
    what is Product wise slow moving / Non-moving?
    thanks,
    kiran.M

    Slow moving is nothing but if i am not using particular Material for last 1 month then i can call this MATNR is Slow Moving MATNR. If i am not using MATNR for last one year it is Non-Moving MATNR.
    Regards
    Prabhu

  • Credit Limit set for Product wise

    HI ,
    We have a requirement of Customer credit limit  has to set at Product ( Material) level , can it be achieved through FSCM Credit Management .
    Say Customer A has Deal with Product X and Product Y , Product X credit Limit : 100000 , B = 200000  overall 300000 for Customer A.
    Regards,
    klreddy

    Hi ,
    As I discribed in example , Sales is to Single Customer , but sales contain multiple products .  As a Business Credit Policy , we required to set up credit limit for each product wise to the same customer .
    Any further information , if you feel , please revert.
    Regards,
    Klreddy

  • Segmented GL A/C Product wise

    Hi All,
    I am using segmented GL a/c and say I have 40 products available to sell.
    Now should I have 40 GL's multiplied my segments for my company?
    Also I will need product wise sale for budgetting purpose.
    Can anyone comment on this please.

    Ajit,
    Your using segmented GL account is a good first step. 
    The 40 products that you sell.  Are they 40 types of Products (Item groups) OR  40 individual items.
    If you are talking about 40 Item groups and would like to track Sales and Cost for each Item group, you have to do the following.
    <b>First and most important</b> - Your Inventory GL should be set by Item Group
    Decide on the segment you are going to use
    Create individual codes within the segment for each Item Group
    Decide on the Natural Account for Revenue and COGS and create them with each segment defined above.
    Now you have a GL Account for each Item group and can setup Budgets.  If your Client wants to track Inventory by Item Group you can chose a natural account from Assets > Inventory and create individual Inventory Account for each Item group.
    Example: 
    Suppose your Item groups are Group A, Group B, Group C .....
    You will have a Code within that segment for each group
    Group A ............... 001
    Group B ................002
    Group B ................003
    Your Revenue Accounts will look like
    4xxxx-001
    4xxxx-002
    4xxxx-002
    Your COGS Accounts will look like
    5xxxx-001
    5xxxx-002
    5xxxx-002
    Your Inventory Accounts will look like
    1xxxx-001
    1xxxx-002
    1xxxx-002
    Let me know if need further clarification
    Suda

  • Product wise COGS

    Dear All
    We need to create Plant wise balance sheet  to meet statutory requirement . And we have maintained  our manufacturing units as segment and as profit centre both. As per process Manufacturing units send goods to Selling Depots and selling depots sold goods to distributor . Sales are getting booked from depot point.
    During PGI ...... 1
    Cost of Goods Sold      Dr.
    To Inventory                Cr.
    During Sales .....2
    Customer A/c            Dr.
    To Sales                 Cr.
    Our requirement is to capture the Product wise Cost of Goods Sold   during PGI ....How to link Cost of Goods Sold with Product. Currently out structure is designed in such way that all mfg.plant and selling depot as profit centre , Departments and Products are cost centres . 
    Please guide us how to config the system in SAP so that we can achieve our above mentioned requirement.
    Thanks in advacne...
    Regards
    Animesh

    Hi
    Whatever you have asked for is pretty standard... I dont know what different you want from it
    Frankly speaking, the goal of FI is not to analyse Product wise COGS... Thats the job of COPA
    however, you can still manage it from FI.. Execute FBL3N with COGS GL account.... Change the layout and include MATNR Field in your Layout... If it is not available, add it as a Special Field from SM30 - Table T021S (BSEG-MATNR)
    MATNR is always updated in te COGS GL Account
    br, Ajay M

  • Profit and Loss Product wise, Customer wise

    Hi Gurus,
    How to generate Profit and loss Product wise and customer wise.
    Product wise - Product cost, sales and Net profit from product
    Customer wise - Product cost sold (COGS) and sales, net profit from customer.
    Please advise.

    F.01 is the T code for you .
    Provide the profit center in the dynamic selection menu for profit center .
    Cheers ,
    Dewang

  • Product wise raw material consumption

    Raw material consumption is not coming correctly product wise (not matched with data extracted through MB51 material consumption report).What will be the possible error?
    N.B. Material Ledger is not active but variant configuration is on.

    Hi
    MB51 contains total movements list which may include material issued to Production as well as to Cost center/Mat moved from one store to other store and so on. where as RM consumption you may be trying to match with the GL In some of the above transactions only material documents are created and FI docs may or may not be created hence the two may not match.
    Regards
    Rajneesh Saxena

  • Character wise count of a word

    Hi
    I want a query to find to find the character wise count of a word.
    Ex..if the word is Marium Thomas
    I just want to get the output as---
    M ------- 2
    A -------- 2
    PLease help me to solve this out.

    Hi,
    Hope this helps for you.
    declare
    a varchar2(1000):='ABBCCCDDDDEEEEE';
    b number;
    c varchar2(100);
    d varchar2(100);
    l number:=1;
    k number:=1;
    count1 NUMBER:=0;
    begin
    select length(a) into b from dual;
    for z in 1..b loop
    dbms_output.put_line('--------------------------------');
    c:= substr(a,l,1);
    if c IS NOT NUll then
         count1 := 0;
    k :=1;
         for j in 1..b loop
         d:= substr(a,k,1);
         if d IS NOT NULL THEN
    if(c=d) then
    count1 := count1+1;
    End if;
    ELSE
    k :=0;
         END IF;
         k :=k+1;
         end loop;
    ELSE
    l :=0;
    END IF;
    l := l+1;
    dbms_output.put_line('Character : '||c||' count : '||count1);
    dbms_output.put_line('--------------------------------');
    end loop;
    end;
    Thanks,
    Vinoth

  • Month wise count

    Hi all,
    i am using oracle 11.2.0.3.0 version. i need to calculate month wise count. see below table, the date
    like 'MM-DD-YYYY'.
    claims from_date end_date member
    C1 11/06/2012 11/20/2012 M1
    C1 11/02/2012 11/20/2012 M1
    C1 11/04/2012 11/15/2012 M1
    C1 10/07/2012 10/15/2012 M1
    C1 09/08/2012 09/09/2012 M1
    C2 05/07/2012 05/08/2012 M1
    C2 06/09/2012 06/15/2012 M1
    I need the output like below
    claims from_date end_date member count(claims) count(member)
    C1 11/06/2012 11/20/2012 M1 3 3
    C1 11/02/2012 11/20/2012 M1 3 3
    C1 11/04/2012 11/15/2012 M1 3 3
    C1 10/07/2012 10/15/2012 M1 1 1
    C1 09/08/2012 09/09/2012 M1 1 1
    C2 05/07/2012 05/08/2012 M1 1 1
    C2 06/09/2012 06/15/2012 M1 1 1
    Thanks.
    Edited by: 980659 on Jan 8, 2013 8:07 PM

    980659 wrote:
    I need the output like below
    claims from_date end_date member count(claims) count(member)
    C1 11/06/2012 11/20/2012 M1 3 3
    C1 11/02/2012 11/20/2012 M1 3 3
    C1 11/04/2012 11/15/2012 M1 3 3
    C1 10/07/2012 10/15/2012 M1 1 1
    C1 09/08/2012 09/09/2012 M1 1 1
    C2 05/07/2012 05/08/2012 M1 1 1
    C2 06/09/2012 06/15/2012 M1 1 1
    Thanks.
    Edited by: 980659 on Jan 8, 2013 8:07 PMWith your changed output, you could use
    select claims, from_date, end_date, member,
            count(*) over(partition by  to_char(from_date,'yyyymm') order by null) claim_count,
            count(*)  over(partition by  to_char(from_date,'yyyymm') order by null) member_count
    from your_table;FROM_DATE and TO_DATE are expected in the same month

Maybe you are looking for