Count of all ebeln for each SUBMI

hi all,
i want to Get count of all EBELN for each SUBMI.
Get EBELN & EBELP from EKPO table.
Get ANFNR from EKPO for the EBELN & pass it in EKKO-EBELN
Get SUBMI from table EKKO for ANFNR = EBELN
Pass the above SUBMI in table EKKO & get all EBELN
Get count of all EBELN for each SUBMI
isuppose there are 3 ebeln with 1 submi that is 555 and 2 ebeln with another submi as 556.
in report i want to display like this.
ebeln1   submi(555)     count no.1
ebeln2   submi 555      count no 2.
ebeln 3  submi 555     count no 3
ebeln 4  submi 556     count no. 1
ebeln 5 submi 556    count no 2..
so on.............
please help me..
regards
steve.

Hi sumit,
Thanks for the reply, can u please help in writing the code to loop through the VO...
I was trying to get the first row and then finding the count of supplier sites, but in each iteration of for loop(for each row) i am getting the same count value for each and every row...
Code :
int j=vo.getrowcount();//count of no. of rows
for (int i=0;i<j;i++)
row=(xxVORowImpl)rowsetiterator.getRowAtRangeIndex(1);
int a=am.getSupplierSitesVO.getRowCount();//this is the view object in the pick list
oapagecontext.writeDiagnostics(this,"value of   a is :"+a,1);
this code is giving row count of last row of supplier.
How to get the count for each and every row of supplier sites ?
Thanks.

Similar Messages

  • Unable to get the row count of supplier site for each supplier

    Hi,
    In the sourcing module, suppliers page is having an advanced table in which there is a field 'supplier' and another filed 'supplier sites' (supplier field is of type picklist).Now, how can i get the count of 'supplier sites' for each supplier???

    Hi sumit,
    Thanks for the reply, can u please help in writing the code to loop through the VO...
    I was trying to get the first row and then finding the count of supplier sites, but in each iteration of for loop(for each row) i am getting the same count value for each and every row...
    Code :
    int j=vo.getrowcount();//count of no. of rows
    for (int i=0;i<j;i++)
    row=(xxVORowImpl)rowsetiterator.getRowAtRangeIndex(1);
    int a=am.getSupplierSitesVO.getRowCount();//this is the view object in the pick list
    oapagecontext.writeDiagnostics(this,"value of   a is :"+a,1);
    this code is giving row count of last row of supplier.
    How to get the count for each and every row of supplier sites ?
    Thanks.

  • Can counter start at 1 for each day automatically? And where to restart?

    Just starting to use Aperture, and am going to be bringing in a lot of photos.
    If possible, I would like each file to be brought in as
    YYYYMMDD 000x
    where x starts at 1 and then increases from there.
    Is there a way to make it reset to 0001 as it imports photos from different days in bulk (better then me having to go back and select just the photos from each day and then restart the counter at 0001)?
    Also, later on I will probably merge photos from others. Is there a way that if Aperture is going to be in additional photos for a day where I already have quite a few, that it knows how to start the counter again where I left off (so there aren't duplicate names)?
    Thanks!!
    MacBook Pro   Mac OS X (10.4.8)  

    Stilllearning
    As far as I know Aperture cannot do this
    However...
    Why not rename the images before you import them and then specify that Aperture uses the original name during import
    Use the most excellent GraphicConverter (http://www.lemkesoft.com/en/index.htm) to rename the images. It has a feature that allows you to do exactly what you want to do. (however - not sure it will be able to help in the second part of your question as the images are already in Aperture.
    In GraphicConverter you will find it in the Other 'gear menu' in the toolbar under:
    Rename -> Index
    Have a look at the other options while you are there.
    Incidentally - I was really hung-up at one stage about image number sequences, trying to retain the original camera index number etc. However - with good EXIF/IPTC data that is not really necessary. As I see it all you want is to never have the same name on 2 images. Forcing the re-use of low digits (0001, 0002, etc) could work against you
    To 'ingest' images I use DIM - a totally brilliant JavaScript
    http://www.alanlight.com/dim/Dim.htm
    It imports the images
    It renames the images
    It puts the images into a date/folder structure in the Finder
    It's free...
    I then 'Import folders into project' in Aperture
    This gives me the correct Finder structure
    It also replicates this folder structure in Aperture
    And I have the best of both world for future peace of mind...
    Files in Aperture
    Files in Finder
    Each backed up via different mechanisms.
    Hope this helps
    Brian

  • SQL help: return number of records for each day of last month.

    Hi: I have records in the database with a field in the table which contains the Unix epoch time for each record. Letz say the Table name is ED and the field utime contains the Unix epoch time.
    Is there a way to get a count of number of records for each day of the last one month? Essentially I want a query which returns a list of count (number of records for each day) with the utime field containing the Unix epoch time. If a particular day does not have any records I want the query to return 0 for that day. I have no clue where to start. Would I need another table which has the list of days?
    Thanks
    Ray

    Peter: thanks. That helps but not completely.
    When I run the query to include only records for July using a statement such as following
    ============
    SELECT /*+ FIRST_ROWS */ COUNT(ED.UTIMESTAMP), TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD') AS DATA
    FROM EVENT_DATA ED
    WHERE AGENT_ID = 160
    AND (TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY')+(ED.UTIMESTAMP/86400)), 'MM/YYYY') = TO_CHAR(SYSDATE-15, 'MM/YYYY'))
    GROUP BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD')
    ORDER BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD');
    =============
    I get the following
    COUNT(ED.UTIMESTAMP) DATA
    1 07/20
    1 07/21
    1 07/24
    2 07/25
    2 07/27
    2 07/28
    2 07/29
    1 07/30
    2 07/31
    Some dates donot have any records and so no output. Is there a way to show the missing dates with a COUNT value = 0?
    Thanks
    Ray

  • Commiting for each record is useful

    Hi All,

    commiting for each record is usefulWhy do you say that? What makes you think it is useful?
    It is all fine for us to tell you that the statement is wrong.. but that will not really address the reasons you think it is useful. So if you can tell the forum of the reasons of your statement, we can show you why those are incorrect and what the correct approach and methodology are.

  • Calculate avg for each record

    Hello,
    what i want is: i have a table
    SCHOOLBOY (id, first_name, last_name, ...)
    and another table
    MARKS (id, schoolboy_id, discipline_id, mark, mark_type). a schoolboy
    on a discipline (e.g. Maths), a schoolboy can have more marks. i wanna calculate the avg of the marks, but for each schoolboy. then, for example i wanna generate a report containing the first name, last name of the schoolboy, and near, the average of the marks.
    how can i calculate the avg of all marks for each schoolboy ?
    Thanks!
    Edited by: Roger22 on 06.06.2009 01:43

    ok, so i post a working case
    create table schoolboys(
    id  numeric(10)     not null,
    first_name   varchar2(50)    not null,
    last_name    varchar2(50),
      CONSTRAINT sch_pk PRIMARY KEY (id)
    insert into schoolboys values (1, 'John','Michael');
    insert into schoolboys values (2, 'Sorin','Wayne');
    insert into schoolboys values (3, 'Aaa','Bbb');
    insert into schoolboys values (4, 'ccc','ddd');
    create table marks(
    id  numeric(10)     not null,
    schoolboy_id integer not null,
    discipline_id integer not null,
    mark number(2) not null,
    mark_type char(1) not null default 'O',
       constraint fk_schoolboyid foreign key(schoolboy_id) references schoolboys(id),
       CONSTRAINT pk_marks PRIMARY KEY (id)
    insert into marks values (1, 1, 4, 10,'O');
    insert into marks values (2, 1, 4, 9,'O');
    insert into marks values (3, 1, 4, 8,'O');
    insert into marks values (4, 3, 2, 10,'O');
    insert into marks values (5, 3, 2, 9,'O');so i created the tables, also i inserted some values. in my example i wanna calculate the avg of the marks for each schoolboy (in this case for 1 and 3) on a specific discipline_id. in that table i can have many schoolboys with many marks at more disciplines. i wanna calculate, for each schoolboy the avg of the marks on a specific discipline.
    Thank you

  • Count() for each group, but only groups having 1+ element like... AND all elements like...

    There are tables(and columns) like:
    'Clients'(clientID)
    'Houses' (houseID)
    'Visits' (clientID, houseID, visit_date)
    'Contracts'(contractID, houseID, clientID, rentDate_from, rentDate_end)
    I have problem with writing MS SQL query of this kind:
    how many visits to houses did each client, before renting one of them?
    Its easy to count total number of Visits for each client, listing all visits + group by clientID and selecting count(*) for each group.
    Lets say this is select_1, and select_2 is listing all Contracts for all clients.
    Select_1 is not answer, because count must be performed only on groups, which:
    -have at least 1 row "like" row in select_2 (it means that at least one of visited houses was rented, because it can happen that client visited few houses, but rented other, not visited house). my idea for this is comparing select_1 and select_2 with:
    "where s1.clientID=s2.clientID and s1.houseID=s2.houseID"
    -each group must have all rows(visits) with date of same day or earlier than contract date
     maybe: "datediff(day, s1.visit_date, s2.rentDate_from) >= 0"

    In future, please provide proper DML, DDL and example data, like I have for you below.
    DECLARE @clients TABLE (clientID INT, name VARCHAR(20))
    INSERT INTO @clients (clientID, name)
    VALUES (1, 'Jonathan'),(2, 'Christopher'),(3, 'James'),(4, 'Jean-Luc'),(5, 'William')
    DECLARE @houses TABLE (houseID INT, address VARCHAR(20))
    INSERT INTO @houses (houseID, address)
    VALUES (1, 'NX01'),(2, 'NCC 1701'),(3, 'NCC 1071A'),(4, 'NCC 1701D'),(5, 'NCC 1701E')
    DECLARE @visits TABLE (clientID INT, houseID INT, visitDateTime DATETIME)
    INSERT INTO @visits (clientID, houseID, visitDateTime)
    VALUES (1,1,'2001-01-01 12:13:14'),
    (2,2,'2001-01-02 12:13:14'),
    (3,2,'2001-01-01 12:13:14'),(3,3,'2001-01-01 12:13:14'),
    (4,4,'2001-01-01 12:13:14'),(4,5,'2001-01-01 12:13:14'),
    (5,4,'2001-01-01 12:13:14'),(5,5,'2001-01-01 12:13:14')
    DECLARE @contracts TABLE (contractID INT IDENTITY, houseID INT, clientID INT, rentStartDate date, rentEndDate date)
    INSERT INTO @contracts (houseID, clientID, rentStartDate, rentEndDate)
    VALUES (1,1,'2001-01-02',NULL),(2,2,'2001-01-02',NULL),(3,3,'2001-01-02',NULL),(4,4,'2001-01-02',NULL),(5,5,'2001-01-02',NULL)
    SELECT contractID, c.houseID, c.clientID, rentStartDate, rentEndDate, cl.clientID, name, h.houseID, address, COUNT(v.clientID) AS visits
    FROM @contracts c
    LEFT OUTER JOIN @clients cl
    ON c.clientID = cl.clientID
    LEFT OUTER JOIN @houses h
    ON c.houseID = h.houseID
    LEFT OUTER JOIN @visits v
    ON c.clientID = v.clientID
    AND c.rentStartDate >= v.visitDateTime
    GROUP BY contractID, c.houseID, c.clientID, rentStartDate, rentEndDate, cl.clientID, name, h.houseID, address

  • Check Box for each row in report -- all rows deleting when pressing DELETE

    Hello experts! I have set up a report with a check box for each row. When I click the DELETE button to delete the selected rows, every single one of the rows get deleted...even the ones that are not selected. I have my process point set to "On Submit - After computations and validations".
    This is my delete process (SHG is the table and SHG_ID is the primary key):
    FOR i in 1..HTMLDB_APPLICATION.G_F01.count
    LOOP
    DELETE FROM SHG
    WHERE SHG_ID = HTMLDB_APPLICATION.G_F01(i);
    END LOOP;
    Also, I've added to query in the region source this line:
    htmldb_item.checkbox(1, SHG_ID) del,
    Where does the "1" come into this? Not sure what I am doing wrong!
    Message was edited by:
    user477193
    Message was edited by:
    user477193

    The 1 (first argument to all the htmldb_item.* APIs) corresponds to the array number in htmldb_application.g_fNN. So 1 will populate array g_f01, 2 will populate g_f02 and so on.
    Your code seems fine, it should delete only the checked rows. Are you sure there is no other process on the page that might be deleting the rows? See if you can put up an example on htmldb.oracle.com

  • I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me?

    I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me? The final result would be a spreadsheet telling there were 8 people from 20 to 39 years old, 14 peolple from 40 to 59 and so on...

    jpqcampos wrote:
    This appears to be an 'input form' using 'Radio Buttons' to select the category. Neither of these features are supported in Numbers '09.
    You can input the data on one table and summarize it on a second table, but the input table will continue to hold data for each event.
    And by using the Reorganize button, you can hide all but two rows of that table to approximate the appearance and performance of an input form.
    Here are the two tables, Data on the left and Summary on the right. Notes below.
    The grey-filled columns in both tables are 'working' columns, and may be hidden (as shown in the image below).
    Data table:
    D1 contains the word "TRUE" (in capital letters). (This row is always shown.)
    D2 is empty, or may contain any value except "TRUE" (This row is always hidden under the Reorganize rule.)The rest of Row 2 of this table requires the data shown: a number outside the range to be counted (999), and two checkboxes, both checked.
    D3 (and filled down the rest of column D):   =AND(OR(B2,C2),NOT(OR(B3,C3)))
    The formula returns TRUE only for the first unused row in the table (ie. the first row for which neither checkbox has been checked)
    Summary table:
    Column A contains labels for the age ranges to be counted.
    Column B contains the same information in the form necessary for the formulas in columns C and D. They need a numeric value, and that value must be the largest acceptable value in the range to be counted.
    C2 (and filled right to column D, then both filled down to row 5):
        =COUNTIFS(Data :: $A,"<="&$B,Data :: B,TRUE)-SUM(C$1:C1)
    Two changes from the previous example:
    COUNTIFS is used to separate the Native and Foreign counts as well as the age range to be counted.
    The amount subtracted from each result is the SUM of the earlier results, and includes the text value in the first cell of the column (which is interpreted by SUM as a zero).
    See note below regarding my earlier formula.
    When the greyed columns are hidden and the checkbox in the Reorganize pane is checked, the two tables will appear as shown below:
    Close the reorganize pane, and the 'data entry form' is ready to use.
    To use, enter the age first, then check one of the boxes.
    As soon as one box is checked, the row will be hidden, and the next (unused) row will be shown.
    Regards,
    Barry
    Note regarding formula in my earlier post:
    The earlier formula will give erroneous results as it subtracts only the count directly above it from its count of persons in the age range 0-n.
    In E2 of that table, replace "-E1" with "-SUM(E1:E$1)
    Fill down to E8.
    Ignore the instructions (in that post) following "Fill down to E8."
    B

  • Select count(*) for each row of a table

    Hello All,
    Following query gives a statistics for each user (how many items he owns, home many tickets authored, how many objects he is subscribed to etc...)
    select auser.userid,
    (select count(*) from item where owner like '%' || auser.id || '%') ITEM_OWNER_CNT,
    (select count(*) from tkt where originator = auser.id) TKT_ORIGINATE_CNT,
    (select count(*) from tkt where assigned_to = auser.id) TKT_QA_CNT,
    (select count(*) from tkt where create_user = auser.id) TKT_AUTHOR_CNT,
    (select count(*) from subscriptions where subscriber_id = auser.id) SUBSCRIPTION_CNT
    from
    user auser
    I was not happy with the performance of this query, so I tried the same using group by. The performance was even worse.
    Is there any other option for me to try? Please advice.
    Thanks,
    Sathish

    Hi, Sathish,
    As SBH said, a lot depends on your data. Please post some sample data (CREATE TABLE adn INSERT statemetns) for all tables, and the results you want from that data. Describe and give examples of any relationships that are not one-to-one..
    You probably want to do joings, like SBH suggested, rather than scalar sub-queries.
    The connection between the auser and item tables
    (select count(*) from item where owner like '%' || auser.id || '%') ITEM_OWNER_CNT,is very suspicious. Perhaps the item table is poorly designed, and the query would be faster if that table were changed. Is changing the design of the item table an option?
    You should be able to get all the information from the tkt table in one pass. It looks like you need to unpivot the data, so instead of one row per ticket (with 3 different people connected to it), there are 3 rows per ticket, each with only 1 person referenced. This is not necessarily a bad table design. Unpivoting, even more than most other things, depends on your database version, so you'll have to tell what version of Oracle you're using.

  • Counting the number of lines for each procedure in a package

    Hi,
    I would like to write a query on USER_SOURCE that can display the number of code lines for each procedure/function in a package.
    Is it possible to write such a query? Maybe by using analytical functions?
    for example in the following example i would like to count the lines between "PROCEDURE proc1 IS" and "END proc1;" and between "PROCEDURE proc2 IS" and "END proc2;"
    SQL> select text  from user_source where name='PKG_TEST' and type='PACKAGE BODY';
    TEXT
    PACKAGE BODY PKG_TEST IS
      PROCEDURE proc1 IS
      BEGIN
        update t1 set EDITION_NAME = 'AAAAAAA';
        commit;
      END proc1;
    PROCEDURE proc2 IS
      BEGIN
       update t1 set EDITION_NAME = 'AAAAAAA';
        commit;
      END proc2;
    END PKG_TEST;thanks for helping

    onedbguru wrote:
    Hopefully some idiot manager isn't trying to use this sort of thing to base their decisions on developer productivity. If so, they ARE idiots. Number of code lines NEVER, EVER, EVER!!! translates into an efficient application. If I were paid by the line, my code would look like:
    select
    1
    from
    dual
    Based on the idiocy of this method of determining "performance" I would get paid $5.00 at $1.00/line. And trust me, I saw this back in the 80's and 90's and saw similar idiotic code and had to clean up the mess. Most of it wasn't efficient code to start with let alone the number of lines generated.Or the other extreme, when the PHB firmly believed that execution efficiency was gained by reducing the number of lines of code. So instead of nicely formatted, easy to read code:
          *GET NEXT ORDER NUMBER                                                               
                EXEC SQL                                                                        
                     SELECT (MAX(ORDER_NUM) + 1)                                                
                     INTO   :NEXT-NUM:IND-NULL                                                  
                     FROM   PART_ORDER                                                          
                END-EXEC.                                                                       
                IF IND-NULL < 0                                                                 
                  MOVE 1 TO NEXT-NUM.                                                           
                EXEC SQL                                                                        
                     INSERT                                                                     
                     INTO    PART_ORDER                                                         
                            (ORDER_NUM,                                                         
                             ORIGIN_LOC,                                                        
                             ORDER_TYPE,                                                        
                             ORDER_STAT,                                                        
                             CREAT_TIME)                                                        
                     VALUES (:NEXT-NUM,                                                         
                             :LOC, 'R', 'O',                                                    
                             CURRENT TIMESTAMP)                                                 
                   END-EXEC.                                                                    
                MOVE NEXT-NUM TO MASK0.                                                         
                PERFORM HEADER-PROC THRU HEADER-EXIT.                                           
            CREATE-ORDER-EXIT. EXIT.                                                     You got this:
           *GET NEXT ORDER NUMBER
            EXEC SQL SELECT (MAX(ORDER_NUM) + 1) INTO :NEXT-NUM:IND-NULL FROM
            PART_ORDER END-EXEC. IF IND-NULL < 0 MOVE 1 TO NEXT-NUM. EXEC SQL INSERT
            INTO PART_ORDER (ORDER_NUM, ORIGIN_LOC, ORDER_TYPE, ORDER_STAT,
            CREAT_TIME) VALUES (:NEXT-NUM, :LOC, 'R', 'O', CURRENT TIMESTAMP)
            END-EXEC. MOVE NEXT-NUM TO MASK0. PERFORM HEADER-PROC THRU HEADER-EXIT.
            CREATE-ORDER-EXIT. EXIT.                 Oh, wait! See the same thing all the time in this forum ... not because someone thinks fewer lines = faster code, but simply because people are sloppy.
    INSERT INTO PART_ORDER(ORDER_NUM,ORIGIN_LOC,ORDER_TYPE,ORDER_STAT,CREAT_TIME) VALUES (:NEXT-NUM,:LOC, 'R', 'O',CURRENT TIMESTAMP) ;

  • Query to count ACTIVE records for each month

    All,
    I have a requirement to count the number of active customers for each month of an year. Let's say, we have 3 fields in the table:
    ID               ActiveStart             ActiveEnd
    1                 1/1/2014               11/30/2014
    In this scenario, the member with ID was active for all the months (Jan-November) EXCEPT, December. So, the result set I am expecting for the Month of January to December is like below:
    Month       CountOfMembers
    Jan            1
    Feb           1
    Mar           1
    April          1
    May           1
    June          1
    July           1
    August      1
    Sept          1
    Oct            1
    Nov           1
    Dec           0 (Since, the member was NOT active in this month)
    Similarly, if you have another member whose start date is 1/1/2014 and termination is '5/31/2014', then, I would need to add 1 for months of January till May, the member WON'T be counted for the rest of the months. So, in this case, the count will be come
    "2" for months January till May, it will remain "1" for June till November and still "O" for December.

    >>I have a requirement to count the number of active customers for each month of an year. Let's say, we have 3 fields [sic: columns are not fields] in the table [sic: tables have names]: <<
    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI-ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need to
    know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI-ISO Standard SQL. And you need to read and download the PDF for: 
    https:--www.simple-talk.com-books-sql-books-119-sql-code-smells-
    There is no magical universal “id” in RDBMS, tables have names and columns have constraints and types. Most of the work in SQL is done in the DDL. Here is a possible schema. 
    CREATE TABLE Duty_Roster
    (member_nbr INTEGER NOT NULL PRIMARY KEY,
     duty_start_date DATE NOT NULL,
     duty_end_date DATE NOT NULL,
    CHECK (duty_start_date <= duty_end_date),
    INSERT INTO Duty_Roster
    VALUES 
    (1, '2014-01-01', '2014-11-30'),
    (2, '2014-01-01', '2014-05-31');              
    >> In this scenario, the member with ID was active for all the months (Jan-November) EXCEPT, December. So, the result set I am expecting for the Month of January to December is like below: <<
    A month is a temporal measurement that makes no sense without a year. But if you knew the ISO temporal model, you would see that you have what is called an INTERVAL data type. T-SQL does not support it yet. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Month_Periods
    (month_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (month_name LIKE  '[12][0-9][0-9][0-9]-[01][0-9]-00'),
     month_start_date DATE NOT NULL,
     month_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (month_start_date <= month_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    SELECT M.month_name, COUNT(R.member_nbr) AS member_cnt
      FROM Month_Periods AS M,
           Duty_Roster AS R
     WHERE M.month_start_date 
           BETWEEN R.duty_start_date AND R.duty_end_date
       AND M.month_end_date 
           BETWEEN R.duty_start_date AND R.duty_end_date;
    We had no business rules about partial months, so I guessed. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • GETTING COUNTS FOR EACH SSN

    I am doing a report in ORACLE REPORT WRITER. How can I get counts for each SSN. I want to check the last 7 SSNS
    and if the competence codes are different get a count for them. If the fitness codes are different get a count for them. This is for each SSN. Sometimes SSNS may have different competence codes but the fitness codes are the same. I still need counts for the competence codes. Other times the SSNS have different fitness codes but the competence codes are the same and I need counts for the fitness codes. Other times the fitness codes are different and the competence codes are different and I need counts for the fitness codes and counts for the competence codes. Here is a sample of what the report should look like:
    SSN TOTAL TOTAL
    Competence Fitness
    000000111 13 6
    000000222 6 0
    000000333 0 7
    I have everything wrapped up under one count. I don't know to change the query to display 2 separate counts.
    I have used Summary Columns but that does not work.
    I could use 2 separate querys and get counts for competence and fitness respectively but the SSNS would be out of order. The SSNS must be in order.
    Here is the query.
    SELECT DISTINCT T2.IND_SSN, COUNT(*)cnt1
    FROM (SELECT distinct(t.ind_ssn), t.ind_competence_rtg_old, t.ind_competence_rtg_new, ROW_NUMBER()
    OVER (PARTITION BY t.ind_ssn ORDER BY t.IND_SSN ASC, t.ind_er_per_end_dt DESC) rn
    FROM NCOER_JRNL T) t2
    WHERE t2.rn <= 7
    and (t2.ind_competence_rtg_old <> t2.ind_competence_rtg_new)
    GROUP BY T2.IND_SSN
    UNION
    SELECT DISTINCT T2.IND_SSN, COUNT(*)cnt2
    FROM (SELECT distinct(t.ind_ssn), t.ind_FIT_rtg_old, t.ind_FIT_rtg_new, ROW_NUMBER()
    OVER (PARTITION BY t.ind_ssn ORDER BY t.IND_SSN ASC, t.ind_er_per_end_dt DESC) rn
    FROM NCOER_JRNL T) t2
    WHERE t2.rn <= 7
    and (t2.ind_FIT_rtg_old <> t2.ind_FIT_rtg_new)
    GROUP BY T2.IND_SSN
    ORDER BY 1

    Thanks for you reply Ricardo. It does work (but only if select 1 ticket).
    My bad I only posted one Ticket Number. Actually there are lots of them ( as below). Your code take all the tickets as one tickets.
    TicketNumber
    OwningTeam
    Status
    Date
    Team Number
    123
    TEAM 1
    Pick Up
    11/12/2014
    1
    123
    TEAM 1
    Complete
    11/12/2014
    1
    123
    TEAM 2
    Pick Up
    11/12/2014
    2
    123
    TEAM 2
    Complete
    11/12/2014
    2
    123
    TEAM 2
    Resolve
    11/17/2014
    2
    123
    TEAM 2
    Complete
    11/24/2014
    2
    123
    TEAM 2
    Pick Up
    12/8/2014
    2
    123
    TEAM 2
    Complete
    12/9/2014
    2
    123
    TEAM 2
    Provide Info
    12/17/2014
    2
    123
    TEAM 1
    Pick Up
    1/8/2015
    3
    123
    TEAM 1
    Resoved
    1/8/2015
    3
    456
    TEAM 1
    Pick Up
    11/12/2014
    1
    456
    TEAM 1
    Complete
    11/12/2014
    1
    456
    TEAM 2
    Complete
    11/24/2014
    2
    456
    TEAM 2
    Pick Up
    12/8/2014
    2
    456
    TEAM 2
    Complete
    12/9/2014
    2
    456
    TEAM 3
    Pick Up
    12/17/2014
    3
    456
    TEAM 3
    Working
    12/18/2014
    3
    456
    TEAM 1
    Pick Up
    1/8/2015
    4
    456
    TEAM 1
    Resoved
    1/8/2015
    4
    789
    TEAM 1
    Pick Up
    11/12/2014
    1
    789
    TEAM 1
    Complete
    11/12/2014
    1
    789
    TEAM 2
    Complete
    11/24/2014
    2
    789
    TEAM 2
    Pick Up
    12/8/2014
    2
    789
    TEAM 2
    Complete
    12/9/2014
    2
    789
    TEAM 1
    Complete
    12/12/2014
    3
    Any work around is really appreciated.
    Thanks,
    Rajneet

  • Help in finding the total count for each month

    Hello everyone,
    Sometime back I had posted about the date function. I have that problem solved now my problem is that after finding all records which against each record I need to find the total count for that month if no records than I have to set it to a 0.
    Here is how my program has been written.
    PROCEDURE extract_materials
    IS
    CURSOR xyz
    BEGIN
    FOR xyz1 IN xyz LOOP
    -- once inside the loop for each of the record from
    the cursor I need to find a total count for that record for everymonth in the year.
    All these records will be instered in to a staging table
    Can you please help me out with this. I really appreciate this.
    Thanks in advance.
    -Vani

    Andrew - you missed the tricky bit of the spec - include missing months with a zero.
    You need to do an outer join to a select from any big table with a function involving rownum and add_months to generate all the possible months. However, its time to go home and I can't be bothered to work out the finer details.

  • I have problem loading all items from XML with for each

    Hi all,
    I'm low level as3 programmer and I need help whit this code:
    I have gallery XML file:
    <gallery>
        <item>
            <id>1</id>
            <strana>0</strana>
            <naslov>Lokacije</naslov>
            <aktuelno>1</aktuelno>
            <slika>1.jpg</slika>
        </item>
        <item>
            <id>2</id>
            <strana>2</strana>
            <naslov>Coaching</naslov>
            <aktuelno>1</aktuelno>
            <slika>2.jpg</slika>
        </item>
        <item>
            <id>3</id>
            <strana>0</strana>
            <naslov><![CDATA[O.Å . Bratstvo - panel]]></naslov>
            <aktuelno>0</aktuelno>
            <slika>3.jpg</slika>
        </item>  
    </gallery>
    And:
    var loader: URLLoader = new URLLoader();
         loader.load(new URLRequest("gallery.xml");
    var xml = new XML(evt.target.data);
        for each(var item in xml..item) {
            centralniText.htmlText = item.slika;
    only shows  last item from XML file:
    3.jpg
    I want all. Please help.

    can adding count item in XML help somehow?
    <gallery>
        <item>
            <id>1</id>
            <strana>0</strana>
            <naslov>Lokacije</naslov>
            <aktuelno>1</aktuelno>
            <slika>1.jpg</slika>
        </item>
        <item>
            <id>2</id>
            <strana>2</strana>
            <naslov>Coaching</naslov>
            <aktuelno>1</aktuelno>
            <slika>2.jpg</slika>
        </item>
        <item>
            <id>3</id>
            <strana>0</strana>
            <naslov><![CDATA[O.Å . Bratstvo - panel]]></naslov>
            <aktuelno>0</aktuelno>
            <slika>3.jpg</slika>
        </item>   
        <last>3</last>
    </gallery>

Maybe you are looking for