Trying to count the number of different occurrences in a SQL statement.

I am trying to achieve a sql statement, taking into account the number of occurrences of date for a person gives. ... Here's my query so far...

----------------------

Select TO_DATE(SUBSTRC(trim(ppei.pei_information4),1,10),'RRRR/MM/DD') start_date, ppei.person_id,.
case
When ppei.person_id = 130385 then count(TO_DATE(SUBSTRC(trim(ppei.pei_information4),1,10),'RRRR/MM/DD'))
END AS count_test
of per_people_extra_info iepp
where ppei.information_type = 'XXPER_CALL_IN_LOG. '
and ppei.person_id = 130385
Group of TO_DATE(SUBSTRC(trim(ppei.pei_information4),1,10),'RRRR/MM/DD'), ppei.person_id
-----
START_DATE PERSON_ID COUNT_TEST
------------------------- ---------------------- ----------------------
MARCH 1, 11 130385 1
MAY 20, 11 130385 1
JUNE 12, 11 130385 1
20 JUNE 11 130385 1
18 AUGUST 11 130385 1

5 selected lines

That's what I want the data to look at...

START_DATE PERSON_ID COUNT_TEST
------------------------- ---------------------- ----------------------
MARCH 1, 11 130385 1
MAY 20, 11 130385 2
JUNE 12, 11 130385 3
20 JUNE 11 130385 4
18 AUGUST 11 130385 5


Is it possible to do this?

There is always a way ;-)
And, if you'd be working with data easy, as I showed you, it would be easier for you and for the people in this forum.
Select the field you need. Don't know what exactly you need to allow you to choose and to strengthen

with test_data as
(
select to_date('01-MAR-11','DD-MON-RR') START_DATE, 130385 person_id, 'yes'  pei_information5 from dual union all
select to_date('20-MAY-11','DD-MON-RR') START_DATE, 130385 person_id, 'yes'  pei_information5 from dual union all
select to_date('12-JUN-11','DD-MON-RR') START_DATE, 130385  person_id, 'no'  pei_information5 from dual union all
select to_date('20-JUN-11','DD-MON-RR') START_DATE, 130385  person_id, 'yes'  pei_information5 from dual union all
select to_date('18-AUG-11','DD-MON-RR') START_DATE, 130385  person_id, 'yes'  pei_information5 from dual union all
select to_date('01-MAR-11','DD-MON-RR') START_DATE, 111111 person_id, 'yes'  pei_information5 from dual union all
select to_date('2-MAY-11','DD-MON-RR') START_DATE, 111111 person_id, 'no'  pei_information5 from dual union all
select to_date('2-JUN-11','DD-MON-RR') START_DATE, 111111  person_id, 'no'  pei_information5 from dual union all
select to_date('3-JUN-11','DD-MON-RR') START_DATE, 111111  person_id, 'no'  pei_information5 from dual union all
select to_date('1-AUG-11','DD-MON-RR') START_DATE, 111111  person_id, 'yes'  pei_information5 from dual)
---
select start_date,person_id,pei_information5,
  count(*) over (partition by person_id order by start_date) count_test,
  count(*) over (partition by person_id,pei_information5 order by start_date) count_test2,
  sum(case when pei_information5 ='yes' then 1 else 0 end) over (partition by person_id order by start_date) count_test3,
  sum(case when pei_information5 ='yes' then 1 else 0 end) over (partition by person_id,pei_information5 order by start_date) count_test4
  from test_data
  order by person_id,start_date;

START_DATE                PERSON_ID              PEI_INFORMATION5 COUNT_TEST             COUNT_TEST2            COUNT_TEST3            COUNT_TEST4
------------------------- ---------------------- ---------------- ---------------------- ---------------------- ---------------------- ----------------------
01.03.2011 00:00:00       111111                 yes              1                      1                      1                      1
02.05.2011 00:00:00       111111                 no               2                      1                      1                      0
02.06.2011 00:00:00       111111                 no               3                      2                      1                      0
03.06.2011 00:00:00       111111                 no               4                      3                      1                      0
01.08.2011 00:00:00       111111                 yes              5                      2                      2                      2
01.03.2011 00:00:00       130385                 yes              1                      1                      1                      1
20.05.2011 00:00:00       130385                 yes              2                      2                      2                      2
12.06.2011 00:00:00       130385                 no               3                      1                      2                      0
20.06.2011 00:00:00       130385                 yes              4                      3                      3                      3
18.08.2011 00:00:00       130385                 yes              5                      4                      4                      4                      

Tags: Database

Similar Questions

  • Trying to count the number of network adapters on the virtual machines

    Hi all

    Have tried to create a script to simply count the number of network adapters in a virtual machine? In all honesty, don't have a clue where to start? I don't know there are a number of 'ownership' but can't seem to figure out how I can integrate this counting cards network

    Thank you very MUCH in advance

    Munster

    Try this way

    $vms = Get-VM
    
    foreach ($vm in $vms)
    {
         $vm | Select @{N = "VMName"; E = {$vm.name} },
              @{N = "VMNICCount"; E = {$vm.Networkadapters.count} }
    }
    

    Inside of the foreach loop, you select in each $vm name and County NIC.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Try to count the number of records where some columns are met

    Using SQL in Toad against an Oracle table, I'm trying to count the number of records in a table where some columns are filled. For
    example, I need to know the total number of records from a table where

    ln_stop_cd is not null - 65000 records
    ln_process_cd is <>- 25000 0 records
    ln_opt_cd is not null - 7500 records

    and the record_type = "A".

    I know that the total individual records as described above. However, I do not know how
    the SQL to show for record_type = 'A' the total count is 97500 records. Any help would be
    appreciated.

    Hello

    It seems that the problem is that the indictment may overlap; You can count the same rank 0, 1, 2 or 3 times, depending on whether 0, 1, 2 or 3 of these 3 independent conditions are met.

    Try something like this:

    SELECT     COUNT (in_stop_cd)
          + COUNT (CASE WHEN in_process_cd  != 0        THEN 1 END)     -- this site doesn't like the other inequality operator
          + COUNT (in_opt_cd)        AS grand_total
    FROM    table1
    WHERE     dt          >= TO_DATE ('01-JUN-2011', 'DD-MON-YYYY')
    AND     dt          <  TO_DATE ('02-JUN-2011', 'DD-MON-YYYY')
    AND     record_type       = 'A'
    ;
    

    You want to make charges without making 3 assists separated through the table. The problem is the 3 original requests had slightly different WHERE clauses.
    Put these conditions in the WHERE clause and make other conditions apply only to the individual counties, either with a column instead of *, or using a CASE statement that contains the condition that applies only to the column.

    Also, the date is not a column name good. Do not compare the DATEs to strings. If your column is really a DATE and you want to ignore the hours, the minutes and seconds, then the best way is to compare the column with 2 other DATES, as shown above. It's more coding, but it is more efficient and more reliable.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    You don't have to display a large amount of data. You can probably give an excellent example of this problem with only 5 or 10 rows of sample data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    Published by: Frank Kulash, August 4, 2011 11:27

  • How to count the number of data records?

    Hey guys, how to count the number of records, I had on a data object variable?

    Im having a result of sql query in a variable like this:

    oDB.resolveNode("#command").query.select.value = "SELECT * FROM Customers WHERE CliNombre LIKE ' % ' + input1 +" %' ";

    oDB.open ();

    oDB.first ();

    So I need to count the number of records retrieved by this SQL query at the moment. Help please

    Then move the cursor back to the first record after you have your account.

    There is a keyword count in SQL that will allow you to get the account of your request. You can run that first - get your account, and then run the actual query to get the Recordset. This would require a separate data connection. Some examples of code.

    var xfa.event.newText = inName;
    If (inName == "") {}
    App.Alert ("you must enter a name--try again!")
    }
    var nIndex = 0;
    While (xfa.sourceSet.nodes.item (nIndex) .name! = "DataConnection2")
    {
    nIndex ++;
    }

    oDB = xfa.sourceSet.nodes.item (nIndex) .racing var (1); pertaining to the specified data connection node
    App.Alert (ODB.saveXML ("Pretty"));

    var nIndex = 0;
    While (xfa.sourceSet.nodes.item (nIndex) .name! = "DataConnection3")
    {
    nIndex ++;
    }
    var oDBCount = xfa.sourceSet.nodes.item (nIndex) .racing (1); pertaining to the specified data connection node
    Configure sql call DB to get the number of records that match the criteria

    oDBCount.nodes.item (1).query.setAttribute ("text", "commandType");
    oDBCount.nodes.item (1).query.select.nodes.item (0) .value = "Select count (*) from table1 where AcctNumber = '" + inName + "'";
    oDBCount.open)
    oDBCount.close)

    Configure sql call DB to get the specified employee number

    oDB.nodes.item (1).query.setAttribute ("text", "commandType");
    oDB.nodes.item (1).query.select.nodes.item (0) .value = "Select * from table1 where AcctNumber = '" + inName + "'";
    App.Alert (ODB. Nodes.Item (1) .saveXML ("Pretty"));

    now connect to the DB and get a recording
    oDB.open)
    oDB.close ();

    Note the SQL command use the keyword count (take a look at the oDBCount section). This will return a number of return to the cllaer. When I set up the data connection, a node count (*) that appeared there. I dragged to the form and it has created a field called count that the onus at this node. When the query is executed, the number of resulting records returns to this field. You can have hidden it so that your users can not see it and also to change the binding votes to zero, so it is not included in the data file that is submitted when the form is complete.

    Paul

  • count the number of occurrence in the table with toplink

    Hello!

    There is no way to create a query with the expressionbuilder or... to count the number of occurences in my table?
    I don't want to use the query " select count (*) from table .

    Thank you

    Not sure about the question. You are looking to get the SQL "select count (*) table" to use the framework of expression TopLink or pull you that SQL already and want something else?

    If you are looking just to get the count of a table/class, you can use a ReportQuery:
    ReportQuery rquery = new ReportQuery (ClassToQueryOn.class);
    rquery.addCount (); equivalent to count (*);

    session.executeQuery (rquery);

    You can use a report query to return data instead of objects and use the criteria for selection as a normal read request.

    Best regards
    Chris

  • Is it possible to do it in a table? (Count the number of days from a certain date)

    Hello

    I did yesterday a data base to make my job easier. I could make it even more effective if I could understand this delicate piece of business.

    What I have is in my table has a column called "Date completed". This column contains the date when the project was completed. Then, I would like to have another column in the table called "number of days elapsed since completion. This column would have simply taken the date in column "Date completed" and count the number of days since that day and show them in a numeric value (i.e. 28). This way I could do a select and display everything is over for a number of days where I need complete my report (s).

    Thanks for any help. If you know a way to do that is completely different from what I'm trying to please do not hesitate to propose a solution, I'm a complete newbie to this. I took a basic SQL course at the College a few years ago, but never learned to do anything as advanced as this.

    Thanks again

    Your number of days can be easily calculated as trunc (sysdate) - date you completed column.

    You probably don't want to store the number of days in the table (since his will change daily)-instead it calculate on the fly that you query the data (or if you have 11 g you could watch the virtual to make columns persistent calculation rather than the value in the table).

  • How to count the number of conditionally highlight cells in a column or row

    I'm working on a table to identify problems with my credit rating. So, I have a column that indicates the due date on the invoice and G that contains the date to which I made the payment.

    I'm trying to follow how many times I'm late with payments. I want to improve.

    So if the G column is later than column D, both with the Date formatting. So, now I've highlighted cells and I want to summarize for the year, how many times I was late payments.

    I thought a column G to count the number of days before or after that back I was with payments. But if the sum, it only gives me no useful information. I guess I could count the number of cells with values less than 0.

    I prefer to be able to put in the summary column for G something that said 0-12 years ago has highlighted cells in the column.

    Thank you

    You can not count based on sharing or formatting.  You can, however, be based on the same conditions.

    There are functions:

    COUNTIF() counties based on a condition is true

    and

    COUNTIFS() based on several conditions being true

    = NB. If

    Here is a way.  IT will take an additional column that calculates the "delay" in the days of a payment

    the first two lines are the lines of header

    H3 = IF (COUNTA (D3, G3) > 1, MAX ((G3−D3) DUR2DAYS, 0), "")

    It's shorthand dethrone select cell H3, and type (or copy and paste it here) the formula:

    = IF (COUNTA (D3, G3) > 1, MAX ((G3−D3) DUR2DAYS, 0), "")

    Now select cell H3, copy

    Select the H3 cells at the end of column H, dough

    H1 = "payments late =" & COUNTIF(H,">0")

  • Count the number of 1 is present in digital waveforms obtained by converting the pulse signals.

    Hello

    I use Analogtodigital.Vi to convert the pulse of the sequences in digital.signals.I am able to get the representation of digital waveforms of impulses.

    But how to count the number of 1 is present in the converted digital waveform. I want to count the number of 1 is present in the digital waveform converted.

    Thanks in advance.

    Have you tried the block scheme of similar to the Digital.vi of opening?

    It creates an array 2D uncompressed 1 and 0, which is the binary 16 bits A/D conversion of each element in the array Y of the input waveform. You can use the DWDT digital Array.vi Boolean to convert a 2D Boolean table. Then convert Boolean values to 1.0 and summarize the array of integers. The sum must be the number of 1 bits in the digital waveforms.

    Lynn

    Note: The VI attached is saved in version 8.6. When I have it saved for the previous Version a warning was generated about the possible differences in the versions. Let me know if it doesn't work, and you are using which version of LV.

  • How to count the number of updates in a loop Forall

    Hi friends

    I want to know is - it possible to count the number of updates occurred in FORALL. I share the codes below. His only return the iteration number. If I spend 5 through the values of the PARAMETERS and 2 updates the values in the table then return 5 instead of 2.  My requirement is to count the number of updates have taken place and return this value to OUTPUT parameter. If possible, please share codes. Thank you very much...

    CREATE OR REPLACE PROCEDURE UPDATE_PROCESS_RATE 
              (
               V_HOSPITAL_ID IN HOSPITAL_SERVICE_MASTER.HOSPITAL_ID%TYPE,
               V_USER IN VARCHAR2,
               V_DATE IN DATE,
               V_PROCESS_ID  IN VARR_ARRAY,
               V_PROCESS_RATE IN NUM_ARRAY,
               V_NUM OUT NUMBER
               )
    
    
                IS
    
                    V_ERROR_CODE NUMBER(15);
                    V_ERROR_MSG VARCHAR2(200);
                    V_ARRAY_ID NUMBER(10,2);
                    V_TOTAL NUMBER:=0;                                            
       BEGIN
                  SAVEPOINT Sp1;
             BEGIN
       
                   FORALL i IN V_PROCESS_RATE.FIRST..V_PROCESS_RATE.LAST
                 
                               UPDATE HOSPITAL_SUBSERVICE_PROCESS M 
                               SET M.PROCESS_CHARGE=V_PROCESS_RATE(i)
                               WHERE M.HOSPITAL_ID=V_HOSPITAL_ID
                               AND M.HOSPITAL_PROCESS_ID =V_PROCESS_ID(i);
                                                        
                   FOR i IN V_PROCESS_RATE.FIRST..V_PROCESS_RATE.LAST LOOP
                
                       V_TOTAL:=V_TOTAL + SQL%BULK_ROWCOUNT(i);
                   End loop;
               
                       COMMIT;  
                       V_NUM:=V_TOTAL;           
    
    
    
    
    

    IndiMinds wrote:

    But my requirement is: it must count the update only when it detects a different value from array. When it detects a different value in the table must be updated and count it and if the update of the table value is similar the TI should not count it.

    For example, if the V_PROCESS_RATE table have these 3 values (10,20,30) and we need to update these 3 values with (10,40,50), so no update, it should return is 2 not 3.

    Thank you

    And then don't update these lines, change your update statement

    UPDATE HOSPITAL_SUBSERVICE_PROCESS M
    SET M.PROCESS_CHARGE=V_PROCESS_RATE(i)
    WHERE M.HOSPITAL_ID=V_HOSPITAL_ID
    AND M.HOSPITAL_PROCESS_ID =V_PROCESS_ID(i)
    AND DECODE(M.PROCESS_CHARGE,V_PROCESS_RATE(i),0,1) = 1;
    
  • How to count the number or lines in the file

    Hi Experts,

    I'm file as source and Oracle as target. My folder that contains some data that will load the target.
    My requirement is that I want to count the number of lines that contains my folder. Please help me how to count the total number of lines in the file.


    THX,
    Sara.

    Hi Sahaveda,

    Now, I tried and it works.

    Sorry my mistake again.

    I created HR. ETL_FILE_LOG as below:

    CREATE THE TABLE HR. ETL_FILE_LOG (numero_fichier varchar2 (10))

    Below the code will run without error:

    import java.lang as lang

    import java.sql SQL

    import of java.lang.String

    Import os

    disadvantages is sql. DriverManager.getConnection ("<%=snpRef.getInfo("DEST_JAVA_URL")%>", "<%=snpRef.getInfo("DEST_USER_NAME")%>", "<%=snpRef.getInfo("DEST_PASS")%>")

    dblinks = cons.createStatement)

    File1 = Open ('c:\EMP.txt','r')

    Count = 0

    Line = file1. ReadLine()

    all online! ='' :

    Count += 1

    Line = file1. ReadLine()

    File1. Close()

    sqlQuery = "insert into HR. "The values of ETL_FILE_LOG (numero_fichier) (" + str (count) + ' ") '.

    rqQuery = dblinks.execute (sqlQuery)

    jerks. Close()

    Concerning

  • How to count the number of nodes under each parent in any given xml

    How to count the number of nodes under each parent in any given xml. for example the xml below was
    books has 3 childern, library [1] has 4, [2] library has 6 and bookshop [3] has 2. is it possible to get the number of tags in a childnode duplicate IE library [1]
    Book1 Tagus repeated twice... vice versa. do we need to make plsql lie we can achieve through sql

    < book >
    < library >
    ABC < book1 > < / book1 >
    BCA < book2 > < / book2 >
    ACR < book1 > < / book1 >
    Lac < Book4 > < / Book4 >
    < / book >
    < library >
    ABC < book1 > < / book1 >
    BCA < book2 > < / book2 >
    ACR < book3 > < / book3 >
    ACR < book3 > < / book3 >
    tray of < bookn_1 > < / bookn_1 >
    adjusted cost base < bookn > < / bookn >
    < / book >
    < library >
    ABC < book1 > < / book1 >
    BCA < book2 > < / book2 >
    < / book >
    < / books >


    I tried this... query.

    Select
    XMLQUERY ('count($doc/Books/Bookstore[1]/descendant::*)' in the way of xmltype ("< books >
    < library >
    ABC < book1 > < / book1 >
    ACR < book1 > < / book1 >
    Lac < Book4 > < / Book4 >
    < / book >
    < library >
    ABC < book1 > < / book1 >
    BCA < book2 > < / book2 >
    < / book >
    (< / books > ')
    as 'doc' of happy return) .getNumberVal () as node_count
    of the double

    Select
    XMLQUERY ('count($doc/Books/descendant::*)' in the way of xmltype ("< books >
    < library >
    ABC < book1 > < / book1 >
    ACR < book1 > < / book1 >
    Lac < Book4 > < / Book4 >
    < / book >
    < library >
    ABC < book1 > < / book1 >
    BCA < book2 > < / book2 >
    < / book >
    (< / books > ')
    as 'doc' of happy return) .getNumberVal () as node_count
    of the double

    How can I get the counts for each parent in a single query

    Published by: user7955917 on August 24, 2012 07:26

    Generic function how you want the query to be.

    If the structure is known in advance, as in your example a 'books' and then a 'library' root element, it's as simple as:

    SQL> select x1.parent_id, x2.child_name, count(*)
      2  from tmp_xml t
      3     , xmltable(
      4         '/books/bookstore'
      5         passing t.object_value
      6         columns parent_id   for ordinality
      7               , child_list  xmltype path '*'
      8       ) x1
      9     , xmltable(
     10         '/*'
     11         passing x1.child_list
     12         columns child_name varchar2(30) path 'name()'
     13       ) x2
     14  group by x1.parent_id, x2.child_name
     15  order by x1.parent_id, x2.child_name
     16  ;
    
     PARENT_ID CHILD_NAME                       COUNT(*)
    ---------- ------------------------------ ----------
             1 book1                                   2
             1 book2                                   1
             1 book4                                   1
             2 bookn                                   1
             2 bookn_1                                 1
             2 book1                                   1
             2 book2                                   1
             2 book3                                   2
             3 book1                                   1
             3 book2                                   1
    
    10 rows selected
     
    

    If you want a generic solution that works without knowledge of the structure, you will need a recursive approach, and most importantly, you should know which nodes in distinct, I suppose that the leafs?

    Also, please help if you can provide the link of reference on the function name() years what are the other expression, that I can use after the path

    You can start reading the documentation: http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb_xquery.htm#CBAGCBGJ

    The clause PATH expects a XQuery expression however before 11.2, we can put only simple XPath expressions.

  • Count the number of flashVars from HTML

    Hi, I'm creating a simple image using AS3 Viewer and get the URL of the image of flashVars in HTML code. I want to use an if argument so that it performs a function if it is single flashVar and another if there is more.

    I read the flashVars very well and can write if statements throughout the day, boredom I feel is counting the number of flashVars from html code. Here a real dumbed down version of what I'm trying to do (which do not work because I can't understand the correct procedure to follow):

    [as]

    var numberOfVars:Number = 0; to store the number of flashVars

    var paramObj:Object = LoaderInfo (this.root.loaderInfo) .parameters; get the flashVars

    for each (paramObj to {LoaderInfo (this.root.loaderInfo) .parameters)}

    numberOfVars + 1;

    }

    var tf:TextField = new TextField();

    addChild (tf);

    TF. Text = numberOfVars.toString (); This returns '0' when runningn this code

    If (numberOfVars < 2) {}

    to do this

    }

    else {}

    to do this

    }

    [as]

    Thanks for your help guys.

    Chris

    I didn't look at the detail of your code, but the next line is probably what you really intend...

    numberOfVars += 1;   not numberOfVars + 1;

  • Count the number of times you click on hot spots.

    The specific problem I'm having right now counts the number of times where an is clicked a hotspot. I have four hot spots and need to track the number of times where is clicked on each hotspot. The variable "tent" gives me the total for the whole interaction. Since they are not considered, I can't use correct or wrong. You have any ideas? I would use the "tries@title" icon, but all the hotspots are contained in the icon interaction so that no longer works.

    Thanks for any help you can provide,

    I often structured interactions so that I can enjoy the variable 'ChoiceNumber. If your access points are all consecutive and they are the first things to the right of the interaction, you can use a variable from the list.

    [ClickList: =]

    Then at the top of each of your answers, you can use

    ClickList [ChoiceNumber]: = ClickList [ChoiceNumber] + 1

    Each task in ClickList is taken into account the time that spot has been used and you can use the sum to get the total of all tasks. If they can not be the first thing then you can always use an offset value... ClickList [ChoiceNumber-4]: = ClickList [ChoiceNumber-4] + 1

    HTH,

    Mike

  • Count the number of times that that a field is filled

    Help!

    I am building a form with fields of number 10 named task1, task2, task3, etc.. Different users may or may not use all of these fields. For example, a user can only fill 7 of these fields of number 10, while another user can use only 5. I need the form to count the number of the task fields were filled and put that number into a numeric field named TotalTasks.

    Any help is appreciated!

    Gene-O

    OK, here is a corrected version. The code on each of the fields for tasks thise was

    Whereas there is a subform Page2. I renmaed subform Page2 and which caused problems on a couple of

    fields on page 1. Then I updated the code of responsibility and disciplinary fields as well. Everything seems to b working now.

    Paul

  • Count the number of comments in a PDF automatically?

    Hello O Experts,

    My documentation team members use Acrobat and Reader 8 and often need to count the number of comments in a PDF file. Is it possible to count the number of comments automatically? We cannot find this feature anywhere and resorting to the manual count. Because PDF documents can contain thousands of comments, it's very tedious. I tried to search the Web and these forums, but the words 'count' and 'comments' are too frequent in other contexts to find something useful...

    Thank you and best regards,

    -M.T.

    Just thought of another potential idea, that you can try if you use Sticky Notes.

    Do a search for Adobe on the generated summary of comments PDF to Word reminder and you will quickly see the number of instances in the document.

    sypark

Maybe you are looking for