Query Help for Running Count

hi i have table with data like below
CREATE TABLE Table1
ID int
,GroupID int
insert into Table1 values(1,1)
insert into Table1 values(2,2)
insert into Table1 values(3,2)
insert into Table1 values(4,1)
insert into Table1 values(5,1)
insert into Table1 values(6,3)
insert into Table1 values(7,3)
insert into Table1 values(7,3)
insert into Table1 values(8,2)
insert into Table1 values(9,4)
insert into Table1 values(10,5)
Here i need the out put with GroupID and the count. The expected output like below
GroupID
Count
1
1
2
2
1
1
3
3
2
1
4
1
             5              1  
I think you got my scenario. For each groupID i need to put the count but with adjusents same GroupID

Hi Akhil,
It looks like your expected is wrong, Try the below:
CREATE TABLE Table1
ID int
,GroupID int
insert into Table1 values(1,1)
insert into Table1 values(2,2)
insert into Table1 values(3,2)
insert into Table1 values(4,1)
insert into Table1 values(5,1)
insert into Table1 values(6,3)
insert into Table1 values(7,3)
insert into Table1 values(7,3)
insert into Table1 values(8,2)
insert into Table1 values(9,4)
insert into Table1 values(10,5)
;WITH FirstCte AS (
SELECT GroupID,id,
ROW_NUMBER() OVER(ORDER BY id) AS rnComplete,
ROW_NUMBER() OVER(PARTITION BY GroupID ORDER BY id) AS rnGroupID
FROM Table1)
, SecondCte AS (
SELECT id,GroupID, count(GroupID) Over(partition by GroupID, rnComplete - rnGroupID) as GroupCnt
FROM FirstCte )
SELECT m.GroupID, GroupCnt
FROM SecondCte AS m
GROUP BY m.GroupID, GroupCnt
Order by MAX(m.ID)
Drop table Table1
GroupID
Count
1
1
2
2
1
2
3
3
2
1
4
1
             5              1 

Similar Messages

  • Need help for array counting

    Any help for array question
    Hello to All:
    I want to tally or count some of the elements that I have in array but not sure how.
    I have for example: int myArray[] = {90,93,80,81,71,72,73,74};My objective is to tally all of the 90's, tally all of the 80's and tally all of the 70's.
    So, the result that I want to have would look something like the following:
    System.out.println ("The total tally number of 90's is " 2 );
    System.out.println ("The total tally number of 80's is " 2 );
    System.out.println ("The total tally number of 70's is " 4 );I do not want to add these numbers, just want to count them.
    Also I want to use a "forloop" to achieve the result intead of just declaring it at 2 or 4 etc..
    Any help Thankyou

    [u]First , This is not exactly what I have to
    do for homework. There is a lot more, a lot more
    involved with the program that I am working on.
    Second, this is an example, an example, an
    example of something that I need to achieve.
    Third, you are asking for a code, to me that
    sounds as if your asking for homework. Fourth,
    I did not ask for any rude comments. Fith, in
    the future please do not reply to my messages at ALL
    if you can not help!!!!
    Sixth, We did not ask for lazy goofs to post here.
    Seventh, In the future please do not post here. Take a hike - there's the virtual door.

  • HELP FOR RUN PHOTOSHOP IN COMMAND PROMPT AND OPEN FILE

    HELLO
    i have problem for run photoshop in cmd(command prompt) and
    open a file immediate
    for example:
    D:\Program Files\Adobe\Photoshop CS>Photoshop.exe -open -f:\1.jpg
    but these not answer
    I need parameter open in photoshop
    please help me
    thanks

    I would right click on 1.jpg. Select Open with... Select Choose default program... Pick Photoshop and make sure you check "always use the selected program to open this kind of file."
    D:\1.jpg
    Would then open photoshop.

  • SQ01 Query Help for (MKPF and MSEG)

    Is their anyway to have the field MSEG-ERFMG show up on the query results as postive or negative color or use a "-" or "+".  Need to try and show whether is was a negative or postive movement.

    F1 help for MSEG-SHKZG
    Debit/credit indicator in revaluation
    This indicator is used for internal program control.
    Please do not change the entry in this field.
    Any changes made could lead to program errors or terminations.
    I guess the "sign" is defined trough this field ("S" - sollen (debit), "H" - haben (credit)). If my assumption is true, you won't be able to see + / - in MSEG-ERFMG simply because this field contains no information on the sign.
    Using ABAP code you can solve it (or in SQ01 you can use calculated field in your query...I'm not sure you can define that calculated field to cover your requirement...).
    Regards,
    Csaba
    Edited by: Csaba Szommer on May 12, 2009 11:20 PM

  • Query help for count

    Hi Experts,
    I have a table like:
    Id item1 item2
    1 a b
    2 x b
    3 b a
    4 x a
    i need take count exact item1,item2 combination should be (a,b) or (b,a).
    Is there any way to get the combinations counts.
    Regs,
    H

    with xx as
    (select 1 id,'a' item1,'b' item2 from dual union all
    select 2 id,'x' item1,'b' item2 from dual union all
    select 3 id,'b' item1,'a' item2 from dual union all
    select 4 id,'x' item1,'a' item2 from dual union all
    select 5 id,'x' item1,'b' item2 from dual union all
    select 6 id,'a' item1,'b' item2 from dual union all
    select 7 id,'b' item1,'a' item2 from dual
    select count(*)  from xx
    where (item1 = 'a' and item2 ='b') OR (item1 = 'b' and item2 ='a');

  • Query help for sales employee sales

    Hi....
    How can we have a query for
    Name of sales employee
    Item group
    Item name
    Total selling amount
    Total sales order
    Total delivery
    Total AR invoice
    Please help
    Thanks a lot

    Hi,
    What Total selling amount do you need? Invoice - Credit Memo?
    How about the other Total, total count or total amount?
    Thanks,
    Gordon

  • Query Help for reporting on last receipt qty

    SBO Version: 8.82 PL11
    Hello Forum,
    I am looking for some help devising a command behind a crystal report. We are hoping to achieve the last receipt quantity. To arrive at this we would like it to get the last GRPO for an item and total the quantity on that particular GRPO. In addition to this, we want to consider all the lines on the document and SUM them.
    At present, the query I have is as follows:
    Select SUM(c0.Quantity) from PDN1 c0 WHERE c0.ItemCode = T1.ItemCode AND Shipdate = (select Max(ShipDate) from PDN1 C0  INNER JOIN OPDN c1 ON c0.DocEntry = c1.DocEntry where C0.Itemcode =T1.ItemCode AND c1.DocStatus <> 'C'))
    Any assistance would be greatly received.
    Thanks
    Sarah

    Hi Sarah,
    Please repost to the SAP Business One Application  space.
    -Abhilash

  • Select query help for Sales order

    Hi Experts,
    I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
    Any help is appreciated. Expecting code samples....Thanks
    Thanks
    Ricky

    hi,
    do like this,
    write a select query for vbak and vbuk as follows.
    delivery status field is <b>lfstk</b> from <b>vbuk</b>,
    and relation field is <b>vbeln</b> from the both the tables.
    reward points if useful,
    regards,
    seshu.

  • Help for total count in a month

    Hello everyone,I am reposting this message with the hope that I will get some help. Please help me I have a deadline to meet and maybe getting late in meeting the deadline.
    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

    Take a look at analytic functions-- they should be just what the doctor ordered.
    Justin

  • Help for run-time menu localization

    I would like to dynamically change the run-time menu according to the predefined language setting. For example, if the setting (may be set up in a txt file) is German, then when the application is running, it automaticall display a german menu. if the setting is spanish, the menu will change to spanish display. Any help will be appreciated.

    The attached VI can dynamically change the run-time menu and short-cut menu based on language.
    帖子被ttrr在07-24-2006 09:12 PM时编辑过了
    Attachments:
    Multi Language Menu.zip ‏13 KB

  • Query help for archive log generation details

    Hi All,
    Do you have a query to know the archive log generation details for today.
    Best regards,
    Rafi.

    Dear user13311731,
    You may use below query and i hope you will find it helpful;
    SELECT * FROM (
    SELECT * FROM (
    SELECT   TO_CHAR(FIRST_TIME, 'DD/MM') AS "DAY"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '00', 1, 0)), '999') "00:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '01', 1, 0)), '999') "01:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '02', 1, 0)), '999') "02:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '03', 1, 0)), '999') "03:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '04', 1, 0)), '999') "04:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '05', 1, 0)), '999') "05:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '06', 1, 0)), '999') "06:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '07', 1, 0)), '999') "07:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '08', 1, 0)), '999') "08:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '09', 1, 0)), '999') "09:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '10', 1, 0)), '999') "10:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '11', 1, 0)), '999') "11:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '12', 1, 0)), '999') "12:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '13', 1, 0)), '999') "13:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '14', 1, 0)), '999') "14:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '15', 1, 0)), '999') "15:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '16', 1, 0)), '999') "16:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '17', 1, 0)), '999') "17:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '18', 1, 0)), '999') "18:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '19', 1, 0)), '999') "19:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '20', 1, 0)), '999') "20:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '21', 1, 0)), '999') "21:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '22', 1, 0)), '999') "22:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '23', 1, 0)), '999') "23:00"
        FROM V$LOG_HISTORY
        WHERE extract(year FROM FIRST_TIME) = extract(year FROM sysdate)
    GROUP BY TO_CHAR(FIRST_TIME, 'DD/MM')
    ) ORDER BY TO_DATE(extract(year FROM sysdate) || DAY, 'YYYY DD/MM') DESC
    ) WHERE ROWNUM < 8;Hope That Helps.
    Ogan

  • Query help for where condition

    Hi ,
    I have String value in table now I require to check that value is valid or not .
    I have below Query .
    SELECT *
    FROM Table TCI
    WHERE (ISDATE(SUBSTRING(SUBSTRING(Data,82,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,82,6),5,2)+'-'+'01')<>1 OR LEN(LTRIM(RTRIM(SUBSTRING(Data,82,6)))) < 0 OR SUBSTRING(Data,82,6)='000000')
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,88,6)))) < 0 OR SUBSTRING(Data,88,6)= '000000' OR ISDATE(SUBSTRING(SUBSTRING(Data,88,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,88,6),5,2)+'-'+'01')<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,173,6)))) < 0 OR ISDATE(SUBSTRING(SUBSTRING(Data,173,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,173,6),5,2)+'-'+'01')<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,195,6)))) < 0 OR ISDATE(SUBSTRING(SUBSTRING(Data,195,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,195,6),5,2)+'-'+'01') <>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,217,7))))<0 OR ISNUMERIC(LTRIM(RTRIM(SUBSTRING(Data,217,7)))) <> 1)
    AND ISNUMERIC(REPLACE(SUBSTRING(Data,334,10),'-','0'))<>1
    AND ISNUMERIC(SUBSTRING(Data,345,10))<>1
    AND ISNUMERIC( SUBSTRING(Data,355,10))<>1
    AND ISNUMERIC(SUBSTRING(Data,416,8))<>1
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,104,6))))<0 OR ISNUMERIC(SUBSTRING(Data,104,6))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,145,7))))<0 OR ISNUMERIC(SUBSTRING(Data,145,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,152,7))))<0 OR ISNUMERIC(SUBSTRING(Data,152,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,159,7))))<0 OR ISNUMERIC(SUBSTRING(Data,159,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,166,7))))<0 OR ISNUMERIC(SUBSTRING(Data,166,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,179,3))))<0 OR ISNUMERIC(SUBSTRING(Data,179,3))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,201,3))))<0 OR ISNUMERIC(SUBSTRING(Data,201,3))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,365,10),'-','0'))<>1 OR ISNUMERIC( REPLACE(SUBSTRING(Data,365,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,375,10),'-','0'))<>1 OR ISNUMERIC( REPLACE(SUBSTRING(Data,375,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,385,10),'-','0'))<>1 OR ISNUMERIC(REPLACE(SUBSTRING(Data,385,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,395,10),'-','0'))<>1 OR ISNUMERIC(REPLACE(SUBSTRING(Data,395,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,405,10),'-','0'))<>1 OR ISNUMERIC(REPLACE(SUBSTRING(Data,405,10),'-','0'))<>1)
    I need only invalid record set from below Query ;
    like; If it is not isdate and is_numeric type for particular row then it return only that row.
    currently i'm facing issue like whole string is invalid in that case it gives row .
    should I use case statement in where clause ?
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

    I need only invalid record set from below Query ;
    like; If it is not isdate and is_numeric type for particular row then it return only that row.
    currently i'm facing issue like whole string is invalid in that case it gives row .
    should I use case statement in where clause ?
    Hi PrajapatiNeha,
    Your requirement is confusing. Judging from the query, the column data
    seems to be a string which consists of fixed length date or numberic format substrings, so you are verifying each substring is valid and need to select the invalid substrings?
    If that is your requirement, why not just extract the substrings into a derived table and filter based on the derived table?  The substrings in the derived table will give a more directly overview of your long data string.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Query Help for SO Alert

    Dear Experts,
    I have a scenario where our user would like to be reminded of action items pertaining to a specific BP when entering a new SO.
    I have the following query but would like it to alert only once.  What syntax do I need to configure for this query to send an internal alert once within a few minutes of adding?
    SELECT T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], 'Reminder: <<Insert Reminder Here>>.' as "Important Message"
    FROM ORDR T0
    WHERE T0.[CardCode] IN ('ABC01')
    Thanks,
    Richard

    Hi
    You may create an alert by:
    SELECT T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, 'Reminder: <<Insert Reminder Here>>.' as "Important Message"
    FROM ORDR T0
    WHERE T0.CardCode IN ('ABC01') AND DateDiff(D,T0.DocDate,GetDate())=0
    However, there is no switch to turn it off.
    Thanks,
    Gordon

  • Urgent Help for Run Report

    after creating a button in form builder 9i i want to fire a tigger for execute the report which is built in report builder 9i but it is not executing and showing me these errors..
    code behind tigger of button is
    Declare
    repid REPORT_OBJECT;
    v_rep VARCHAR2(100);
    rep_status VARCHAR2(20);
    Begin
    repid := FIND_REPORT_OBJECT( ' c:\rsoreport.rep ' );
    or ( ' rsoreport.jsp ' );
    or ( ' rsoreport ' );
    v_rep := RUN_REPORT_OBJECT(repid);
    End;
    error = FRM-41219 : Cannot find the Report: invalid id; on Form
    and on Status bar Run_Report_Object cannot be null.
    i need to execute the report behind form button so if any one know the simple code for this or tell me my code mistake then i would be very thanfull to him

    You need to post this in forms forum. But you can check this. It has example how to run report from forms.
    http://www.oracle.com/technology/products/forms/pdf/frm9isrw9i.pdf

  • Need help for encoder count program !!!!!!!!!

    I am a new labview user.
    And i am trying to complete a project for my course.
    For a quick background on what I am working with, I am using a NI PCI-73566-Axis Stepper/Servo Motion Controller for PCI, NI UMI-7764 Series, NI USB-6009 and a IDEC SC1B Rotary Encoder.
    I am try to design a encoder count program and a new program to convert the encoder signal to RPM.
    But I just don't know where should I start? How can I get the same block diagram like P11 in the attach file?
    Please check more detail from the attach file.
    Attachments:
    P11.jpg ‏127 KB
    P8.jpg ‏149 KB
    P15.jpg ‏141 KB

    Hello,
    The two objects on the block diagram are DAQ Assistants and can be found under Functions»Measurement I/O»NI-DAQmx. From what I can gather, this is acquirign signals that you should have connected to the USB-6009.
    -Zach
    Certified LabVIEW Developer

Maybe you are looking for

  • Resetting a Centro

    I have to say that as a long term plam use I find the methond of resetting the Centro requiring the back cover being pulled off and the battery removed is the absolutely most assinine manner of resetting a device of this type I have seen. The fool wh

  • Color correction for newsprint

    Anybody out there know of a slick quick way to adjust color, in Freehand 10, for graphics eps files ultimately being printed on newsprint? My graphics and illustrations always seem to be washed out, as if all the colors need to be maybe 20% darker. T

  • Gateway and routes

    Hi all, I hope you can help me understanding gateways a little better. I am trying to build a workflow where I need to diverge the flow to two different departments. Therefore I chose the gateway for this task (I guess thats what the gateway is suppo

  • I don't know my security questions and don't know what to do it won't let me use iTunes even though I know my password what do I do?

    I don't know my security questions what do I do?

  • Webservices using GenericSoapService

    Hi everyone, I'm calling the GenericSoapService through SoapUI to validate some services (Since soap wsdl's and the Webservices wsdl wizard is not supported anymore in 11g). And I'm not able to validate (get anonymous as the user in my call) ¿do I ha