Group by range of 10 (amount)

Hi all,
I have a table of 400,000 records like this:
But I need grouped by amount of 10 and count the number of clients grouped, something like this:
I hope the pictures explain better my problem.
Thanks for your support
Carlos

Create a table like this ---
GroupTens
Start
End
Group
0
10
Group 0 to 10
11
20
Group 11 to 20
21
30
Group 21 to 30
31
40
Group 31 to 40
41
50
Group 41 to 50
51
60
Group 51 to 60
61
70
Group 61 to 70
71
80
Group 71 to 80
81
90
Group 81 to 90
91
100
Group 91 to 100
101
110
Group 101 to 110
111
120
Group 111 to 120
121
130
Group 121 to 130
131
140
Group 131 to 140
141
150
Group 141 to 150
<tfoot></tfoot>
Then this query with your table and field names --
SELECT DISTINCT CarlosDante.Account, (SELECT COUNT([XX].ClientID) FROM CarlosDante AS [XX] WHERE [XX].Account = CarlosDante.Account AND [XX].Amount BETWEEN START AND END) AS ClientCount, (SELECT SUM([XX].Amount) FROM CarlosDante AS [XX] WHERE [XX].Account
= CarlosDante.Account AND [XX].Amount BETWEEN START AND END) AS SumOfAmount, GroupTens.Group
FROM CarlosDante, GroupTens
WHERE ((((SELECT COUNT([XX].ClientID) FROM CarlosDante AS [XX] WHERE [XX].Account = CarlosDante.Account AND [XX].Amount BETWEEN START AND END))>0))
ORDER BY CarlosDante.Account, GroupTens.Group;
Build a little, test a little

Similar Messages

  • Customer Account Group Number Range

    Hi Guru's,
    The Customer Account Group Number Range has currently taking 10 digits. But my client wants to be 12 digits.
    Could you please guide me, to do the necessary setting for the same.
    Kindly suggest.
    thanking you,
    regards,
    Sreeni

    Dear Sreeni,
    You can't change standard customer no range flied width.
    You can create a new ZTABLE with 12digits.
    regards
    natraj

  • Reg: Vendor Account Group Number Range

    Hi Guru's,
      I have created 3 Account groups for vendor -
    MV- Material Vendor , SV - Service Vendor , Ov - One Time Vendor
    And i need to number range (external) like this for MV- MV10000 to MV19999 and SV - SV10000 to SV19999
    i tried by XKN1 but the system says Enter the intervals without overlap .
    Guide me to achieve this.
    Thanks in advance
    Regards
    Anand

    Hi
    Thanks for your solution.. It means my intervals falls under a to zzzz.
    i have a query A to  ZZZZZ is alphanumeric or alphabetic?
    Can we set the range only as alphabetic .. that is no numeric is allowed .
    Regards
    Anand

  • Group by range

    Hi friends
    In one of report i have to group by some range.for ex
    I have to show the no of students and the total marks in a report for less<100 marks then marks>100 and <200 and like wise
    no of accts totalmarks
    1.upto 100
    2over 100 and less than 200
    how the above result can be achieved by simple sql
    Thanks in advance

    Hi,
    dj wrote:
    thanks for quick reply but case statement will give me the result in a single row if I am not wrong, but i want the result in tabular form.I showed how to group rows into ranges. You can then do whatever you want to with that range value. For example, you can use the range value to pivot the results into a tabular form.
    Please post some sample data (CREATE TABLE and INSERT statments) and the exact results you want from that data, formatted and posted between \ tags.
    Explain how you get those results.  In particular, explain how ranges are determined.
    Say which version of Oracle you have.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SSRS Chart grouped by range of values

    Hello,
    Can you guys assist in the following scenario where I have two columns  "Staff"  and  "Age"
    Staff     Age
    John      23
    Bob       25
    Mike      27
    Caren   35
    Bonny   42
    I'm trying to build a Column chart in SSRS 2008 that would Count th number of staff in every age range (20's , 30's, 40's)
    I'm hoping to get three columns in the chart : one field for the 20's  with 3 people in it;    and two other columns for the 30's and 40's with one staff in each.
    I can't figure out the expression that should be used in the categories group of the chart.
    thanks in advance

    Thanks Elvis for a gr8 solution, i followed your solution but with that i got another problem,
    please help me to solve this,
    Now my problem is, if Data set bind with chart do not have any row for a particulate category (like "8-14 Days") then chart is not showing data for in with 0 value,
    my requirement is if no data available for a age category Zero value is to be displayed like,
    Please help me on this.. it is urgent for me...

  • Grouping a range of numbers into a like group

    I am trying to group credit scores by risk value.  The data that I'm pulling in is a number an I want to convert it to a letter. 
    So anything over a score of 700 is A credit for example.  Anything between 660 and 699 is B Credit, between 630 and 659 would be C Credit and so on.
    Currently the data comes in from the databas as a string field(dont make sense to me either), the string field is a number anywhere from 0 to 800.  I do understand that I will have to convert the string to a number and then probably a SELECT CASE statement, but I'm lost from there.  My current select case looks like this
    select CDbl({APPLIC_DATA.AP_RISK_SCORE})
        Case Is >= 700:
        "A"
        Case 660 To 699:
        "B"
        Case 630 To 659:
        "C"
        Case 580 To 629:
        "D"
        Case 1 To 579:
        "E"
        Case 0:
        "No Score"
    This is not working for me.  I was thinking that it would change my numbers in this field to the correct letter that corresponds to that number and I could group from there, but that obviously is not what is happening.
    Any help would be appreciated.

    I'm sorry I have one more issue that I discovered here and cant seem to fix.  Some of the fields are blank and have no data so I have tried...
    if tonumber({APPLIC_DATA.AP_RISK_SCORE})>=700 then
    "A"
    else if tonumber({APPLIC_DATA.AP_RISK_SCORE}) in 660 to 699 then
    "B"
    else if tonumber({APPLIC_DATA.AP_RISK_SCORE}) in 630 to 659 then
    "C"
    else if tonumber({APPLIC_DATA.AP_RISK_SCORE}) in 580 to 629 then
    "D"
    else if tonumber({APPLIC_DATA.AP_RISK_SCORE}) in 1 to 579 then
    "E"
    else if tonumber({APPLIC_DATA.AP_RISK_SCORE})=0 then
    "No Score"
    else "No Score"
    Along with other such as:
    else if tonumber({APPLIC_DATA.AP_RISK_SCORE})="" then
    "No Score"
    All with no outcome.  The field just remains blank.  What am I doing wrong here?

  • SAP buffer for Customer Account Group (number range skipping)

    Dear Experts,
    When creating new customer for Account Grp = TRDL for my company, I find out that the number range always skip and this problem continues. Someone told me to check it out if the problem might comes from buffer. In Tcode = SNRO (Object = DEBITOR) I find out that buffer setting = 5.
    The Question is how can I check if this buffer rate is compatible with my SAP environment? or which rate is more compatible and help solve the problem of number range skipping?
    If anybody have some suggestion please feel free to contribute it.
    Thank you very much

    Hi,
    in SNRO, take out the flag for
    "Main memory buffering".
    SAP recommends:
    Dependencies
    When buffering number intervals, gaps may result in number assignment. Buffering is therefore not possible for applications, which require continuous number assignment.
    What happens is that the system loads consecutive numbers into the buffer, in your case these are five consecutive numbers. When you create customers and do not use all the numbers already in the buffer, the numbers remain open. Example: You start XK01 for customer creation, create three customers and then logoff. You have two open numbers remaining. Numerical example: 1, 2, 3 have been used, 4 and 5 have been reserved, but are open.
    When invoking XK01 again after subsequent log-on, the system pulls the next five numbers into the buffer. Since 1,2,3,4,5 were already taken (for the previous buffer), the next buffer goes from 6 to 10.
    Numbers 4 and 5 will never be used, the practical consequence of that are the number gaps that you have noticed.
    Hope this helps.
    Rudolf

  • Query help - Group by range of program set

    Need help in developing query with the following set of data.
    Program
    req_id
    parent_id
    runtime
    A
    1
    -1
    30
    A1
    2
    1
    20
    A2
    3
    -1
    1
    A3
    4
    3
    5
    A4
    5
    -1
    7
    A5
    6
    -1
    4
    A6
    7
    -1
    3
    A1
    8
    1
    10
    A2
    9
    -1
    1
    A3
    10
    9
    2
    A4
    11
    -1
    3
    A5
    12
    -1
    2
    A6
    13
    -1
    2
    The results I am looking for is in the following format.
    Set
    G1
    G1_time
    G2
    G2_time
    G3
    G3_time
    Set1
    G1
    6
    G2
    11
    G3
    3
    Set2
    G1
    3
    G2
    5
    G3
    2
    Can you please tell if this can be achieved using sql in Oracle 11g?
    Thanks very much.

    Hi,
    Depending on your requirements:
    WITH   got_grp AS
        SELECT  program
        ,       LAST_VALUE ( CASE
                                 WHEN  program = 'A1'
                                 THEN  req_id
                             END
                             IGNORE NULLS
                           ) OVER ( ORDER BY  req_id ) AS grp
        ,       req_id
        ,       runtime
        FROM    a
    ,   got_c_num    AS
        SELECT  DENSE_RANK () OVER (ORDER BY grp) AS grp_num
        ,       runtime
        ,       CEIL ( ROW_NUMBER () OVER ( PARTITION BY  grp
                                            ORDER BY      req_id
                     / 2
                     )     AS c_num
        FROM    got_grp
        WHERE   program  NOT IN ('A', 'A1')
    SELECT     'SET' || grp_num    AS "SET"
    ,          'G1'                AS g1
    ,          g1_time
    ,          'G2'                AS g2
    ,          g2_time
    ,          'G3'                AS g3
    ,          g3_time
    FROM       got_c_num
    PIVOT     (    SUM (runtime)
              FOR c_num  IN ( 1 AS g1_time
                            , 2 AS g2_time
                            , 3 AS g3_time
    ORDER BY  grp_num
    Output:
    SET        G1    G1_TIME G2    G2_TIME G3    G3_TIME
    SET1       G1          6 G2         11 G3          3
    SET2       G1          3 G2          5 G3          2

  • Using member sorting and grouping with two reports sharing rows

    Hi!
    I have a problem with one report and I need some help or advise here.
    I have two dimensions with dynamic expansion in rows (PRODUCT, MATERIAL), and I use the option Member Sorting and Grouping at Member selector to obtain the total amount of PRODUCT group by PARENTH1:
    PRODUCT               MATERIAL          AMOUNT
    TOTAL PROD_A-X                                   100
    PROD_A_A             MAT1                          22
    PROD_A_B             MAT1                          50
    PROD_A_A             MAT2                          28 
    TOTAL PROD_B-X                                   120
    PROD_B_A             MAT1                          30
    PROD_B_A             MAT2                          50
    PROD_B_B             MAT2                          40
    This works fine if I only have one report, but I need to create another one sharing the row and page axis with the Default Report, when I do that the option Member Sorting and Grouping doesn't work. I really need to have two reports with shared rows and also the summation by PARENTH1, how can I do that?
    Thank you very much

    Hi!
    I have a problem with one report and I need some help or advise here.
    I have two dimensions with dynamic expansion in rows (PRODUCT, MATERIAL), and I use the option Member Sorting and Grouping at Member selector to obtain the total amount of PRODUCT group by PARENTH1:
    PRODUCT               MATERIAL          AMOUNT
    TOTAL PROD_A-X                                   100
    PROD_A_A             MAT1                          22
    PROD_A_B             MAT1                          50
    PROD_A_A             MAT2                          28 
    TOTAL PROD_B-X                                   120
    PROD_B_A             MAT1                          30
    PROD_B_A             MAT2                          50
    PROD_B_B             MAT2                          40
    This works fine if I only have one report, but I need to create another one sharing the row and page axis with the Default Report, when I do that the option Member Sorting and Grouping doesn't work. I really need to have two reports with shared rows and also the summation by PARENTH1, how can I do that?
    Thank you very much

  • How to select header group with detailed data in one SQL

    Dear,
    I would like to have a little help from you. My goal is to create a view where data must be in appropriate format. In this format i would like to have for each group one header.
    I have 3 tables which they ar connected to each other (representing hierachical data where financial plan breaks across different groups).
    CRM_PLAN
    CRM_PLAN_ID
    DATE
    AMOUNT
    CRM_PLAN_PE
    CRM_PLAN_PE_ID
    TITLE
    AMOUNT
    CRM_PLAN_ID (ref key to CRM_PLAN.CRM_PLAN_ID)
    CRM_PLAN_MONTH
    CRM_PLAN_MONTH_ID
    YEAR
    MONTH
    AMOUNT
    CRM_PLAN_PE_ID (foreign key to CRM_PLAN_PE.CRM_PLAN_PE_ID)
    Data looks like:
    CRM_PLAN
    CRM_PLAN_ID | DATE | AMOUNT
    1 | 01.01.2012 | 500
    2 | 01.02.2012 | 200
    CRM_PLAN_PE
    CRM_PLAN_PE_ID |TITLE | AMOUNT | CRM_PLAN_ID
    1 | Organization 1 |100 | 1
    2 | Organization 2 |400 | 1
    3 | Organization 3 |200 | 2
    CRM_PLAN_MONTH
    CRM_PLAN_MONTH_ID | YEAR | MONTH | AMOUNT | CRM_PLAN_PE_ID
    1 | 2012| 1 | 60 |1
    2 | 2012| 2 | 40 |1
    3 | 2012| 1 | 350 |2
    4 | 2012| 2 | 50 |2
    5 | 2012| 1 | 200 |3
    I would like view which would return data like:
    MONTH | AMOUNT
    Organization 1 |null
    1 | 60
    2 | 40
    Organization 2 | null
    1 | 350
    2 | 50
    Organization 3 | null
    1 | 200
    The main question is hot to write an sql as source for view to insert before each group a row with title column value from table CRM_PLAN_PE. Is that even possible? Maybe you could suggest me some other method.
    View will be used in oracle form where will be possible to edit data - I will arrange that through insted of trigger.
    Regards,
    Igor
    Edited by: user5528050 on 29.11.2012 2:23
    Edited by: user5528050 on 29.11.2012 2:24
    Edited by: user5528050 on 29.11.2012 2:25

    Hi, Igor,
    user5528050 wrote:
    ... I would like view which would return data like:
    MONTH | AMOUNT
    Organization 1 |null
    1 | 60
    2 | 40
    Organization 2 | null
    1 | 350
    2 | 50
    Organization 3 | null
    1 | 200
    The main question is hot to write an sql as source for view to insert before each group a row with title column value from table CRM_PLAN_PE. Is that even possible? Maybe you could suggest me some other method. So, you want to have 2 different kinds of rows in the output:
    (1) "parent" or "master" rows containing data from crm_plan_pe, such as
    MONTH          AMOUNT
    ==============     ======
    Organization 1(2) "child" or "detail" rows containing data from crm_plan_month, such as
    MONTH          AMOUNT
    ==============     ======
    1          60Sure, you can do that.
    One way is to do a UNION of 2 separate queries: (1) to generate just the parent rows, (2) to generate just the child rows.
    You could also join the 2 tables and use GROUP BY GROUPING SETS. The super-aggregate rows would be the parent rows.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved (it looks like crm_plan is not involved in this problem), and also post the results you want from that data. You need to post this whether or not you want SQL code in reply. The people who want to help you want to provide good answers, and that means they want to re-create the probelm and try their ideas.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • IP Address Value within a range

    I have this table:
    GROUP_UID
    GROUP_NAME
    IP_VALUE_LOW
    IP_VALUE_HIGH
    It is used to control the grouping of ranges of IP Address. I need help on two things with this table. I am sure the solution to one will lead me to the other.
    1. When given an IP_VALUE I need to return the GROUP_UID/NAME that IP_VALUE falls into. I can not use the normal between IP_VALUE_LOW and IP_VALUE_HIGH becuse the IP Value is not truly consecutive.
    13150400 = 192.168.200.0
    13150402 = 194.168.200.0 not 192.168.200.2
    13150403 = 195.168.200.0 not 192.168.200.3
    13150404 = 196.168.200.0 not 192.168.200.4
    13150405 = 197.168.200.0 not 192.168.200.5
    so 13150403 in not between 13150402 and 13150404
    but 192.168.200.3 is between 192.168.200.2 and 192.168.200.4
    2. A group is added or updated. I need to ensure that two groups do not overlap ranges.
    Any Help would be great!!!

    This is the funtion I use now to convert an IP Address to an IP Value:
    FUNCTION IPAddressToIPValue2 (in_IPADDRESS VARCHAR2)
        return NUMBER
    IS
        v_OCTET4 NUMBER;
        v_OCTET3 NUMBER;
        v_OCTET2 NUMBER;
        v_OCTET1 NUMBER;
        v_IP1 VARCHAR2(20);
        v_IP2 VARCHAR2(20);
        v_IP3 VARCHAR2(20);
        v_IP4 VARCHAR2(20);
    BEGIN
        if length(in_IPADDRESS) > 15 then    
            return -3000000000;
        end if;
        select
            max(decode(portion,1,piece)),
            max(decode(portion,2,piece)),
            max(decode(portion,3,piece)),
            max(decode(portion,4,piece))
        into
            v_IP1,
            v_IP2,
            v_IP3,
            v_IP4
        from (
                select
                    seq portion,
                    substr('.'|| in_IPADDRESS ||'.',instr('.'|| in_IPADDRESS ||'.','.',1,seq)+1,
                    instr('.'|| in_IPADDRESS ||'.','.',1,seq+1) - instr('.'|| in_IPADDRESS ||'.','.',1,seq) - 1) piece
                from (select 1 seq from dual union all select 2 from dual union all select 3 from dual union all select 4 from dual));
                v_OCTET4 := to_number(v_IP4);
                v_OCTET3 := to_number(v_IP3);
                v_OCTET2 := to_number(v_IP2);
                v_OCTET1 := to_number(v_IP1);           
                if v_OCTET1 not between 0 and 255 or v_OCTET2 not between 0 and 255 or v_OCTET3 not between 0 and 255 or v_OCTET4 not between 0 and 255 then
                    return -3000000000;
                else
                     return
                     case
                         when v_OCTET4 < 127 then
                            v_OCTET4 * power(2,24) + v_OCTET3 * power(2,16) + v_OCTET2 * power(2,8) + v_OCTET1
                         else
                            v_OCTET4 * power(2,24) + v_OCTET3 * power(2,16) + v_OCTET2 * power(2,8) + v_OCTET1 - power(2,32)
                     end;          
                end if;
    END IPAddressToIPValue2;would I just:
                     return
                     case
                         when v_OCTET4 < 127 then
                            v_OCTET1 + v_OCTET2 * power(2,8) + v_OCTET3 * power(2,16) + v_OCTET4 * power(2,24)
                         else
                            v_OCTET1 - power(2,32) + v_OCTET2 * power(2,8) + v_OCTET3 * power(2,16) + v_OCTET4 * power(2,24)
                     end;           Message was edited by:
    Chris Wendell

  • Grouping of measures in accounts dimension Essbase

    I am new to essbase .
    I am developing a cube for one of the requirements which has got
    following measures in accounts dimension
    1) Allocated quantity
    2) Picked Quantity
    3) Shipped Quantity
    4) Allocated Amount
    5) Picked Amount
    6) Shipped Amount
    Now I want to group these measures in 2 groups viz a) Qtys b) Amounts
    means
    Qtys : Allocated quantity
    Picked Quantity
    Shipped Quantity
    Amounts : Allocated Amount
    Picked Amount
    Shipped Amount
    wanted to show these groups along with its measures in Excel add in report .
    I am using Essbase Integration Services 11 to develop the metaoutline
    How to define these groups in accounts dimension
    Regards
    Amit

    If you have a way to differeniate these measures you can add user defined measures in EIS. One way you could differeniate them is to put in filtering sql the uses like clauses to select members with Quantity or amount in them and have them put under the headings you want

  • Urgent Pl help :Cannot insert Order Group in KONK

    I am not able to insert new Order Group in KONK the number range i select for the Group get added in the number range interval but i can not see any order group which i am trying to insert.
    I have check the transaction SU53 for any authorization object issue but there is no such issue and system is showing the message authorization check was successful.
    Please help its urgent
    points will be awarded

    Hi
    For internal order group number ranges try in T.code: KOT2_OPA
    select the order for which you want to change the number range
    click on change button at the number range, select order group again,
    go to Intervals menu and click on Maintain it will allow you to change the number ranges.
    Regards
    Prasad
    Accenture - Hyd

  • How to suppress a group with a sum of $0

    Post Author: MarkO
    CA Forum: General
    Hi
    I am trying to develop a report with groups of account numbers and amounts.  The detail section is suppressed leaving only the group footer showing the account number and group total $.  I would like the report to only show groups where the total $ is not equal to $0 without leaving any gaps or spaces in the report.  BTW I am fairly new to crystal reports.
    Thanks,
    Mark

    Post Author: Aron Sereny
    CA Forum: General
    this is really easy to do,   you need to bring up the section expert and in there under the formule for suppress enter your suppress condition...somethink like
    sum( account) = 0
    the suppress needs a boolean, so this will return a true or false

  • Is it possible to achieve Group By....Having functionality in Discoverer?

    Hello All,
    I need to print amount due for each customer when it is negative (less than zero). i.e. sum of all transactions against the customer should be less than zero. This is simple through sql if we write "select sum(amount) group by customer having sum(amount) < 0".
    But I need to do this in discoverer. Now the issue is I need to pass two parameters at runtime. First one will be Date (<= as_of_date) and another one will be having multiple values (in clause).
    If I base my report on underlying report view which uses 'group by... having' sql as described above, I will have to use parameter sheet and use syscontext to pass parameters.
    Instead, it will be easier if i pull in all the data in discoverer report and then use parameters to filter it out. But then is there any way to group on customer and having clause to print only those customers where sum(amount) < 0?
    Anish

    Hi Russ,
    I am new to discoverer so pardon me if I am not able to get you quickly.
    I am sorry, but I did not get you when you say calc1 = SUM( CASE WHEN amount <0 then amount ELSE 0 END).
    May be I was not able to describe you problem. Below is the SQL statement that will give me desired results. I want to achieve same results in Discoverer by getting rid of outer select query with grouping. I will be passing org_id and GL date as parameters.
    select customer_number, name, sum(amount_due) Amount_Due, org_id, Business_Segment
    from
    SELECT hca.account_number customer_number, hp.party_name NAME,
    aps.trx_number, aps.gl_date,
    aps.amount_due_remaining amount_due, aps.class, aps.org_id org_id
    ,hca.attribute3
    FROM apps.ar_payment_schedules_all aps,
    apps.hz_cust_accounts hca,
    apps.hz_parties hp
    WHERE aps.org_id IN (570, 573)
    AND aps.gl_date <= '30-NOV-2008'
    AND aps.class in ('CM','INV','DM')
    AND aps.customer_id = hca.cust_account_id
    AND hca.party_id = hp.party_id
    group by customer_number, name,org_id, Business_Segment
    having sum(amount_due) < 0
    order by 1
    Hope I am able to explain you now.
    Thanks,
    Anish

Maybe you are looking for

  • Polling of the current file from multiple files in the FTP Server

    Hello Experts I am working on a file to file scenario.We have to poll the file from the FTP server which may contain multiple files with different creation dates.The requirement is to poll only the file created in the current date.Could anyone throw

  • Printing ALV list with ADS (pdf printer) in non-english charset

    Hello! I have an issue about printing alv list with pdf printer in non-english charset. We have two printers. One for alv lists (SWINCF: Casc.Fonts SAPWIN Unicode) and one for pdf forms(adobe document service). I want to use one printer for any docum

  • Toshiba Front Operation Panel/Illumination Keys not working

    I am unable to toggle wireless on/off, mute/unmute, play/pause using Front operation panel LED keys on my Toshiba Qosmio F60. Currently I need to enable WiFi/Bluetooth from within Windows for it to work. Fn+F8 toggle works as soft block/unblock only

  • Query on Backend Plug-In

    Hi All It is suggested in the MAM configuration guide that the backend should have "Plug-In 2004.1 SP01” .If there is any new version of the Plug-In that can fit here then please suggest me that. Thanks Gopi

  • DVD SP unexectedly quits on build

    We've created a project with a "Play All" button linking to one track, and a "Select" button linking to the first of seven Chapter Select menus, with buttons linking to stories containing the relevant chapters. There is nothing complex about the menu