Running or Cumulative count based on multiple columns

Hello-

I created a table ZZCEL_CUST_TRIAL as follows:

CREATE TABLE 'RPT_MART '. "" ZZCEL_CUST_TRIAL ".

(

NUMBER OF "ORD_DAY_DW_ID."

NUMBER OF "DAYPART_DW_ID."

NUMBER OF "PRODUCT_DW_ID."

NUMBER OF "ACCOUNT."

KEY CONSTRAINT PRIMARY 'PK_CUST_TRIAL' ('ORD_DAY_DW_ID', 'DAYPART_DW_ID', 'PRODUCT_DW_ID')

)

The data of the table looks like this (sample data)

PRODUCT_DW_ID ORD_DAY_DW_ID DAYPART_DW_ID COUNTIES

5588                             2                                  3316                        6

5587                             2                                  1323                        3

5578                             2                                  1323                        3

5564                             1                                  1323                        8

5592                             1                                  793                          7

5580                             1                                  3206                        4

5592                             1                                  1708                        4

5589                             2                                  3316                        2

5566                             1                                  1323                        2

5603                             3                                  3316                        4

The column of numbers actually shows how many customers have bought this product in this range that day. Now, I want to get a (cumulative) current account of customers of each target and each product so basically the output will look like this:

Daypart_dw_id Product_dw_id RUNNING_COUNT

2                                                3316                                   8

3                                                3316                                   12

I'm trying to use this query to get the number of race, but the figures are not good...

SELECT DISTINCT CTR. DAYPART_DW_ID, CTR. PRODUCT_DW_ID

SUM (CTR. COUNTIES) (CTR ORDER. DAYPART_DW_ID, CTR. COUNTIES OF PRODUCT_DW_ID LINES BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING)

OF rpt_mart. ZZCEL_CUST_TRIAL CTR

That's what I have which is obviously not correct. How can I get a count of the number of CHARGES and target products. Thanks in advance for any help. Much appreciated!

DAYPART_DW_IDPRODUCT_DW_IDCHARGES
1295765
12223140
12338856
152399870
152399894
152400087
152

400234

Select

DAYPART_DW_

PRODUCT_DW_ID

sum (sum (counts)) on cumulative_sum (partition by order PRODUCT_DW_ID of DAYPART_DW_)

from the data

Group

PRODUCT_DW_ID, DAYPART_DW_

order by

PRODUCT_DW_ID, DAYPART_DW_

DAYPART_DW_ PRODUCT_DW_ID CUMULATIVE_SUM
1 793 7
1 1323 10
2 1323 16
1 1708 4
1 3206 4
2 3316 8
3 3316 12

Tags: Database

Similar Questions

  • How to concatenate values based on multiple columns of data duplicate in the loop

    Hi all

    Select '100' col_1, '111111' col2 of double

    Union of all the

    Select '100' col_1, '222222' col2 of double

    Union of all the

    Select '101' col_1, '333333' col2 of double

    Union of all the

    Select '102' col_1, '333333' col2 of double

    I need to write by using cursor loop (configurable) so, it must concatenate col_1 or col_2

    If,

    In the table

    col_1, col_2

    100 111111

    100 222222

    101 333333

    102 333333

    Then

    col_1, col_2

    100 111111,222222

    333333 101 102

    Is it possible to compare and concatenate values in the loop

    I have more than 4,000 bytes in the table of col_1,col_2 data values

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Ok then:

    create a type that makes "grouped" clob

    CREATE or REPLACE TYPE clob_obj IS OBJECT
    (
    CLOB theClob
    ORDER MEMBER FUNCTION equals (in_clob_obj IN clob_obj) RETURN NUMBER
    member function getClobVal return clob)
    /

    CREATE or REPLACE TYPE clob_obj BODY
    IS
    FUNCTION MEMBER ORDER is equal to (in_clob_obj IN clob_obj)
    RETURN NUMBER
    IS
    BEGIN
    RETURN sys.dbms_lob.compare (SELF.theClob, in_clob_obj.theClob);
    END;
         
    Member return clob getClobVal function
    is
    BEGIN
    Return self.theClob;
    end;
    END;
    /

    WITH conc_table AS (SELECT 1111 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL

    SELECT 2222 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL

    SELECT 3333 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL

    SELECT cust_id 4444, "CCC" cust_no, ordr_no ' 123456' OF DOUBLE UNION ALL

    SELECT cust_id 5555, "CCC" cust_no, '454545' ordr_no OF DOUBLE UNION ALL

    Select cust_id 66666, "CCC" cust_no, ordr_no ' 77777' DOUBLE UNION ALL

    SELECT cust_id, "CCC" cust_no, ordr_no ' 77777 66666' FROM DUAL)

    SELECT rtrim (XMLAGG (XMLELEMENT (E, cust_id_no, ',')). EXTRACT ('customer_id //text()').getClobVal (),',')

    clob_obj (ord_number) .getClobVal)

    cust_num

    FROM (SELECT cust_id_no

    cust_num

    rtrim (XMLAGG (XMLELEMENT (E, ord_num, ",")). EXTRACT ('//text ()') .getClobVal (), ',') ord_number

    FROM (SELECT DISTINCT cust_id_no, cust_num, ordr_no AS conc_table FROM ord_num cust_no cust_id)

    GROUP BY cust_id_no

    cust_num)

    GROUP BY clob_obj (ord_number)

    cust_num;

    I got the distinct in the select more intimate for no duplicate of the basetable is only sent to reunification of...

    HTH

  • Get the cumulative values in a single column based on another column in reports

    Hi all

    I have a requirement to get cumulative values based on another column.
    I 'Sales rep name' in the first column.
    Correspondent "Values of the invoice line" in the second column.
    Want to have cumulative of all the values for each sales invoice line.
    Then apply rank and display the top 10 sales reps based on invoice lines.
    Since there is no rank option in the PivotTable, I do this in the report table.

    Looking for the best entries...

    Thanks in advance...

    Try below
    2nd column: "name of Sales rep.
    column 2: SUM ("invoice line values ' BY 'Name of Sales rep'") and sort this field desc.
    3rd column: fx RANK (SUM ("invoice line values" BY "Sales rep name")), to hide this column, so that you don't confuse your users.

    and put the filter on the 3rd column below 5

    I hope this works for you

  • How do you count multiple columns of a field in a table

    How do you count multiple columns of a field in a table

    Select count (*)

    of user_tab_columns

    where table_name = 'YOUR_TABLE '.

  • Gears - error when you try to insert values into a table with multiple columns

    Hello

    I started playing with the gears and SQlLite today and I get an error when I try to insert values into a table with multiple columns.

    I have:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text, DeveloperAge int)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?, ?)', [devName, devAge]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I get the error:

    net.rim.device.api.database.DatabaseException; insert into developers values (?,?): SQL logic error or missing database.

    I use this reference: http://code.google.com/apis/gears/api_database.html

    Everything works if I have only one field as:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?)', [devName]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I use the plug-in Visual Studio 2.0 for 2008 that are running Windows XP SP and Simulator 2.13.0.56

    Thank you

    Davy

    Yes, a SQLite database will persist between battery pulls.  The database is registered either to internal MEM or removable media (not the device memory), depending on which is available on your device.

    In general, its not considered a best practice to remove your table as soon as it is empty and re - create it again when you want to add data.  This adds extra overhead fresh for the final, delete and insert first for a given table.  Instead, define and finalize your drawing before you create your table.  Once created, review the static schema.

    That being said, for development purposes, it may be easier to provide an easy way to drop your tables while you develop your schema.

    See you soon,.

    Adam

  • CSS3 multiple columns and Internet Exploder

    I have developed a web page that needs a two column layout and has decided to use CSS3 to describe the columns: very simple:

    {.twocol}

    border-style: solid;

    border width: 7px;

    border-color: #0476ac;

    -webkit-border-radius: 20px;

    -moz-border-radius: 20px;

    border-radius: 20px;

    -moz-column-count: 2;

    -moz-column-gap: 20px;

    -webkit-column-count: 2;

    -webkit-column-gap: 20px;

    number of columns: 2;

    column interval: 20px;

    padding: 10px;

    height: 300px;

    }

    CSS bold described the two-column layout that I want.

    Looked in Internet Exploiter version 9 and it failed. And, since the text was missing I did the 'old skool' method:

    {.colLeft}

    Width: 410px;

    }

    {.colRight}

    Width: 410px;

    float: right;

    }

    Then in HTML:

    < section class = "twocol" >

    < div class = "colRight" >

    < p > right column of things comes here < /p >

    < / div >

    < div class = "colLeft" >

    Insert here the stuff left column < p > < /p >

    < / div >

    < / section >

    I have commented things in "BOLD" in my style sheet.

    Here's my question:

    Since I'm on the HTML5 Shiv, shouldn't that have created the support for multiple columns in CSS3 declarations or is it simply too complex?

    HTML5 Shiv, as its name suggests, is strictly for the support of HTML5 tags in pre - IE9.  It will not help you with CSS level 3.

    Nancy O.

  • GROUP BY with multiple columns.

    I have a little query on the GROUP BY clause.

    Sometimes, we will give several names of columns in GROUP BY. If it behaves in the same way as ORDER BY (multi-column) I wish I had an example where I can use GROUP BY multiple columns. in any case regardless of his behaviour, it will be really appreciated if someone can explain a scenario where GROUP BY with multiple columns can be used.

    I know about the use of GROUP BY aggregate functions, but using a single column.

    Thank you.. !!!

    No, not like that

    I think that Group by does not follow any order...

    If we execute like this

    SELECT registrationid, dateofbirth, sum (age) FROM prawin62 WHERE registrationid = 22 GROUP BY dateofbirth, registrationid.

    22     1/23/1975     54
    22     5/18/2011     330
    

    It will give the same result based on date of birth...

    ~ Praveen

  • Merge multiple columns into a single column?

    Hello

    I need to perform queries dynamically and the return values. I need to retrieve the values of the queries in a single column only by concatenating multiple columns. I can't use the PL/SQL in my scenario.
    is it possible to run a query and the result will be extracted in a single column (multiple column values must be concatenated)?

    Thank you
    Raja.
    SELECT rtrim(extract(xmltype(REPLACE(column_value,'
    

    Check this box... Copy it directly to this

    Ravi Kumar

  • SQL query * I want to insert a file column in the other table based on two columns

    I want to insert a column records to another table based on two columns

    the query below does not work

    insert into def_ver_lnki_p (job_name)

    Select def_job.job_name

    from def_job where def_job.job_id = def_ver_lnki_p.job_id and def_job.table_id = def_ver_lnki_p.table_id;

    Just to correct sql

    Update

    def_ver_lnki_p define job_name =)

    Select def_job.job_name

    of def_job

    where def_job.job_id = def_ver_lnki_p.job_id

    (and def_job.table_id = def_ver_lnki_p.table_id);

  • How to update a record, if it is a composite key (primary key is based on two columns) in the OPS? page?

    Hello

    Actually I got to know this update of a record must be made when the primary key is based on two columns.

    Previously, I used SPEL for a column. It was working fine.

    But I came to know that regardless of the folder I try to update, it was the update page is coming up with the first combination of the record.

    As if RC 131

    RC 124

    RC 125 are the records.

    If I click on update of RC 124 also, the update page is coming up with RC 131 values as it is the first.

    So I understand that the SPEL should be based on two parameters, because it is a composite key.

    How to do?

    Please let me know if you don't understand the problem.

    Thank you.

    Wow!

    I got it.

    Thank you brothers, always a hope that you could help me

  • Update multiple columns from multiple tables in a single UPDATE request

    Hello

    I'm trying to figure if I'm heading in the right direction.

    I want to update multiple columns from multiple tables in a single UPDATE request. Also, I would like to update multiple columns in a table from the tables.

    Scenario 1

    UPDATE Table2, Table 3
    SET T2.Column1 = T1.Column1 
    ,T2.Column2 = T1.Column2
    ,T3.Column2 = T1.Column2
    FROM Table1 T1, Table2 T2, Table3 T3
    WHERE T1.id = T2.id
    and T1.id = T3.id
    
    

    Scenario 2

    UPDATE Table3
    SET T3.Column1 = T1.Column1 
    T3.Column2 = T1.Column2
    ,T3.Column3 = T2.Column3
    ,T3.Column4 = T2.Column4
    FROM Table1 T1, Table2 T2, Table3 T3
    WHERE T3.id = T1.id
    and T3.id = T2.id
    
    

    Hello

    For scenario 1, you must write separate instructions UPDATE table2 and table3.

    To guard against someone else change one of these tables while you act so you can copy all relevant data in a global temporary table and update this global temporary table table3.

    ENGAGE only when two tables have been changed.

    You can write a procedure or an INSTEAD OF trigger to do all this.

    For scenario 2, you can reference many tables that you need when new table3.  It might be more efficient and simpler to use the MERGER rather than UPDATED.  For example:

    MERGE INTO table3 dst

    WITH THE HELP OF)

    SELECT t1.id

    t1.column1

    t1.column2

    t2.column3

    t2.column4

    FROM table1 t1

    JOIN table2 t2 ON t1.id = t2.id

    )             src

    WE (dst.id = src_id

    WHEN MATCHED THEN UPDATE

    SET dst.column1 = src.column1

    dst.column2 = src.column2,

    dst.column3 = src.column3,

    dst.column4 = src.column4,

    ;

  • Make multiple columns while placing text in InDesign CC 2015

    I used to be able to drag all by placing a text file and press the right arrow key before releasing the mouse to create multiple columns within a text. Which seems more to work in InDesign CC 2015.

    Is this a bug or Adobe changed the way it works?

    I just tested in CC 2015 and CS6.

    What works is when you slide on a block of empty text with the text tool, by pressing the right arrow key divides the image into two columns. (This works also when creating other images).

    In both versions of InDesign, when you place a text file or Word, this shortcut does not work.

    We must therefore create first part of two columns of text, then place the text in the frame.

  • How can I create sequential shooting (1 for each 'row') numbers in a script in multiple column?

    How can I create sequential shooting (1 for each 'row') numbers in a script in multiple column?

    Sorry, but for now there no such function to put sequential numbers in the column number drawn.

  • Concatenate multiple columns in a single string

    Hello

    I use Oracle 11.2, how can I concatenate values from multiple columns in a string with an SQL:

    create table testTb (number (5) classId, class varchar2 (32));

    Insert into the testTb value (101, 'room101');
    Insert into the testTb value (101, 'room201');
    Insert into the testTb value (101, 'room301');
    Insert into the testTb value (202, 'room444');
    Insert into the testTb value (202, 'room555');

    I would like to generate the result as following:

    Class 101 is room101, room201, room301
    202 class is located in room444, room555

    Thank you

    Please post sample data.
    11.2 you can use LISTAGG:

    SQL> select 'Class '||classid||' is in '||listagg(classroom, ', ') within group (order by classroom)
     str
      2  from   testtb
      3  group by classid;
    
    STR
    --------------------------------------------------------------------------------
    Class 101 is in room101, room201, room301
    Class 202 is in room444, room555
    
    2 rows selected.
    
    SQL> 
    
  • How do column filter based on another column

    In my report, I have column a thru d. I would like to create a filter based on another column where column is column B. I can enter a value that the column cannot be equal to, but I would use a column instead of a value.

    Thank you.
    Jonathan

    Try this: icon on the filter columns->-> convert this advanced filter for SQL
    You can reference any other column

    BTW: Have you had a chance to look at my suggestion for your post
    Tables from a Table

Maybe you are looking for