How to group using SQL for the required output.

hi all,
i'm currently using oracle 10.2.0.4.0
create table script :
CREATE TABLE FORTEST
( gpno VARCHAR2(10 BYTE),
  classnumber  VARCHAR2(10 byte),
  age_min NUMBER,
  age_max NUMBER,
  amount NUMBER)insert statement:
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 01,0,29,1)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 01,30,35,2)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 01,36,40,3)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 02,0,29,1)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 02,30,35,2)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 02,36,40,5)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 03,0,29,1)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 03,30,35,2)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G123' , 03,36,40,3)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G124' , 01,0,29,1)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G124' , 01,30,35,2)
insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
('G124' , 01,36,40,3) output required:
gpno    classnumber    age_min    age_max    amount
G123    1,3                0        29        1
G123    1,3                30       35        2
G123    1,3                36       40        3
G123    2                  0        29        1
G123    2                  30       35        2
G123    2                  36       40        5
G124    1                  0        29        1
G124    1                  30       35        2
G124    1                  36       40        3since for gpno g123, classnumber 1 and 3, the rates are same across all age_min and age_max they need to be grouped together.
even though gpno 123 classnumber 2 has same rates as classesnumber 1 and 3 for age bands 0 to 29 and 30 to 35,
the rates are different for age bands 36 to 40. so it should not be grouped together. how can i do this in SQL
any help is appreciated.
thanks in advance.

Hi,
Tricky problem!
Unfortunately, LISTAGG was only introduced in Oracle 11.2. About half of the complexity here is the string aggregation, that is, forming the list of classnumbers, such as '1,3', using only functions available in Oracle 10.2.
Here's one solution:
WITH     got_gpno_classnumber_cnt   AS
     SELECT     gpno, classnumber, age_min, age_max, amount
     ,     COUNT (*) OVER ( PARTITION BY  gpno
                                  ,            classnumber
                      )   AS gpno_classnumber_cnt
     FROM    fortest
--     WHERE     ...     -- If you need any filtering, this is where it goes
,     pairs          AS
     SELECT    a.gpno
     ,       a.classnumber
     ,       MIN (b.classnumber)
                OVER ( PARTITION BY  a.gpno
                          ,                    a.classnumber
                  )     AS super_classnumber
     FROM       got_gpno_classnumber_cnt  a
     JOIN       got_gpno_classnumber_cnt  b  ON   a.gpno     = b.gpno
                                  AND  a.age_min     = b.age_min
                                AND  a.age_max     = b.age_max
                                AND  a.amount     = b.amount
                                AND  a.gpno_classnumber_cnt
                                        = b.gpno_classnumber_cnt
     GROUP BY  a.gpno
     ,            a.classnumber
     ,       b.classnumber
     HAVING       COUNT (*)     = MIN (a.gpno_classnumber_cnt)
,     got_rnk          AS
     SELECT DISTINCT     
             gpno, classnumber, super_classnumber
     ,     DENSE_RANK () OVER ( PARTITION BY  gpno
                               ,                    super_classnumber
                               ORDER BY          classnumber
                       )         AS rnk
     FROM    pairs
,     got_classnumbers     AS
     SELECT     gpno, classnumber, super_classnumber
     ,      SUBSTR ( SYS_CONNECT_BY_PATH (classnumber, ',')
                   , 2
                 )     AS classnumbers     
     FROM     got_rnk
     WHERE     CONNECT_BY_ISLEAF = 1
     START WITH     rnk             = 1
     CONNECT BY     rnk             = PRIOR rnk + 1
          AND     gpno             = PRIOR gpno
          AND     super_classnumber  = PRIOR super_classnumber
SELECT DISTINCT
       g.gpno
,       c.classnumbers
,       g.age_min
,       g.age_max
,       g.amount
FROM       got_gpno_classnumber_cnt  g
JOIN       got_classnumbers         c  ON   c.gpno        = g.gpno
                             AND  c.classnumber  = g.classnumber
ORDER BY  g.gpno
,            c.classnumbers
;Output (just as you requested):
GPNO       CLASSNUMBERS       AGE_MIN    AGE_MAX     AMOUNT
G123       1,3                      0         29          1
G123       1,3                     30         35          2
G123       1,3                     36         40          3
G123       2                        0         29          1
G123       2                       30         35          2
G123       2                       36         40          5
G124       1                        0         29          1
G124       1                       30         35          2
G124       1                       36         40          3

Similar Messages

  • How can i use AME for the new OAF page.

    Dear all,
    I have developed a new OAF page and registered under Employee Self Service.
    How can i use AME for the approval process.
    Appreciate your ideas?
    zamora

    I will try to answer based on my experience of working with iProcurement and AME. It depends on how you want to make a call to AME , directly from OAF Page or from Workflow and your requirement. You didn't specify what you want to show the users on OAF Page and your business requirement.
    Before calling AME Engine from the OAF page or workflow, I guess you did already setup AME Transaction Type and it's Approval Groups, Conditions, Action Types and Rules. Do some testing from AME Business Analyst Test Workbench. Please note that, AME provides lot of PL/SQL API's that you have to call from your programs (java or workflow pl/sql)
    Let's look at the workflow and putting an OAF Page as notification.
    As Sameer said, you have kick-off workflow process from PR of CO and with in the workflow function, you make a call to AME Engine API's with the AME Transaction ID. This transactionId belongs to the AME Transsaction Type that you setup. Based on the rules setup, AME Engine generates list of approvers/approver and stores them AME Tables for that transactionId. Then, it sends a notification to the approver.
    In the workflow, where that notification is defined, in the message body you have to put an attribute(&XX_WF_FWK_RN) of type document/send. And this attribute will have the constant JSP:/OA_HTML/OA.jsp?OAFunc=XX_FUNC&paramId=-&DOCUMENT_ID-. This function is SSWA Jsp function that makes a web html call to your OAF Region.
    If your requirement is to just show the list of approvers on the OAF Page, you may have to call AME API diectly passing your AME TrasnactionId with other parameters. Then AME generates list of approvers and stores them in AME tables with each approver status. You can pickup those approvers using VO and show them on OAF Page.
    Hope this gives some idea.

  • How do i use ichat for the 4gs, how do i use ichat for the 4gs

    i would like to know how to start using ichat on my new 4gs ?

    Hi,
    There is no iChat on the iOS 5 devices
    However iChat on a Mac can send SMS messages to a Phone - Providing the computer  thinks it is in the United States and the Phone is serviced by a USA Carrier that takes part in the AIM Forwarding service.
    8:07 PM      Saturday; October 22, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How to group order & AR for the customers under one customer hierarchy

    There are serveral customers under one customer hierarchy, we could easily get the group value in COPA (KE30) via
    the "customer hierarchy" parameter in the navigation channel. Could we also get the group value towards the incoming sales
    order and Account Receivable? Thanks for the suggestion...

    Hi,
    Please check "FDM_COLL01". It is very useful report, you can drill down the report inside aswell.
    Rgds
    Murali. N

  • How to frame a SQL for the below Query

    i have a SQL query
    select x,y from table1 where x=1
    output
    x y
    1 a
    1 b
    where a means alpha and b means beta
    select x,z from table2 where x=1
    Output
    x z
    1 B
    How do i build a query to achieve a following output
    x z y1 y2
    1 b alpha beta
    Please noete : Instead of 'a' and 'b' i want it to be replaced by words and
    i want two rows value to appear in one column together....

    Maybe this is what you want ... I'm under the impression of trying to catch a moving target here.
    WITH tb_clr_doc_version_defs AS (SELECT 'A' datatype_cd,
                                            13  doctype_id
                                       FROM dual
                                      UNION
                                     SELECT 'A' datatype_cd,
                                            14  doctype_id
                                       FROM dual
         tb_clr_doc_field_defs AS (SELECT 'AccountNb_ID' fieldname_nm,
                                          13             doctype_id
                                       FROM dual
                                    UNION
                                   SELECT 'TaxIDNb_NO' fieldname_nm,
                                          13           doctype_id
                                       FROM dual
    SELECT datatype,
           MAX(DECODE(fieldname_nm, 'AccountNb_ID', fieldname_nm, NULL)) fieldname_nm1,
           MAX(DECODE(fieldname_nm, 'TaxIDNb_NO'  , fieldname_nm, NULL)) fieldname_nm2
      FROM (SELECT t1.doctype_id,
                   DECODE(t1.datatype_cd, 'A', 'afp', 'L', 'line', 'M', 'mixed', t1.datatype_cd) datatype,
                   t2.fieldname_nm
              FROM tb_clr_doc_version_defs t1,
                   tb_clr_doc_field_defs   t2
             WHERE t1.doctype_id = t2.doctype_id(+)
    GROUP BY doctype_id, datatype
      ;

  • How do I use firesync for the first time across 3 systems with different bookmarks? How do I combine initially?

    If I have a need for firesync, it stands to reason that I have previously been using 2 systems. So my first step is to combine the 2 firefox profiles, but I do not see documentation for this

    Duplicated.
    https://support.mozilla.com/en-US/questions/853267

  • How does group message work for the iphone5?

    I want to send out the same message to everyone instead of creating a new thread for each person and I don't want them to see the names of the other people that I am sending it to. Does turning of group message prevent the group chat or will they still everyone's names? Thanks.

    This happening because you guys are sharing the same apple id, you can continue to share it or create a separate one for each user.  You'll have to make sure that for icloud - each users have their own apple id.
    Then go into settings - message - send&receive - make sure the phone number is the default.

  • How do I arrange for the Premiere output to be as near the same as the input as possible?

    A newbie question.
    I am editing a ten minute video down to a 90 second clip, with an added jpeg and a watermark. The first (http://www.youtube.com/watch?v=YQ3UOlHY3GE) turned out fine in terms of HD and widescreen. The second (http://www.youtube.com/watch?v=wgin-kBcep8) has not – it’s all scrunched. They both started out as identical format [1920x1080, 14005kbps data rate, 14133kbps total bitrate, 50 frames/second) MP4 files; the good output format is a (1920x1080, 25920kbps data rate, 2630kbps total bitrate, 25 fps) “Movie Clip”, whereas the poor output is a (720x576, 28807kbps data rate, 30343kbps total bitrate, 25fps) “Video Clip”.
    How do I arrange it for the Premiere output to be as near the same as the input as possible, so as to present in YouTube as HD and fully widescreen? My guess is that I am doing something stupid when I open the incoming file.

    Stephen,
    In your initial post, you state:
    They both started out as identical format [1920x1080, 14005kbps data rate, 14133kbps total bitrate, 50 frames/second) MP4 files;
    If that is correct, then you ARE starting out with full-HD material, and that should be a PAR = 1.0 (Square Pixels) and 16:9 Aspect Ratio. Outputting to 1920 x 1080, should yield 16:9 with Square Pixels, as well.
    Now, one of your output tests WAS to SD, and you state:
    the poor output is a (720x576, 28807kbps data rate, 30343kbps total bitrate, 25fps) “Video Clip”.
    but there is no mention of that output file's PAR, so it could be 4:3, or 16:9. The down-rezzed Export file WILL not look as good as full HD output to full HD.
    I think that that latter 720 x 576 confused Harm, or maybe I am the one, who is confused?
    Good luck,
    Hunt

  • How to create a new variant and a job sheduled to use it for the ......

    How to create a new variant and a job sheduled to use it for the exisisting programs

    Hi
    1. The ALV Grid Control is a tool with which you can output non-hierarchical lists in a
    standardized format. The list data is displayed as a table on the screen.
    The ALV Grid Control offers a range of interactive standard list functions that users need
    frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list,
    export list (in different formats), and so on. These functions are implemented in the
    proxy object class. You as the programmer have the possibility to turn off functions not
    needed. In most cases the implementations of the standard functions provided by the
    control are sufficient. However, if required, you can adjust these implementations to
    meet application-specific needs.
    You can add self-defined functions to the toolbar, if necessary.
    The ALV Grid Control allows users to adjust the layout of lists to meet their individual
    requirements (for example, they can swap columns, hide columns, set filters for the
    data to be displayed, calculate totals, and so on). The settings (list customizing) made
    by a specific user are called a display variant. Display variants can be saved on a userspecific
    or on a global basis. If such display variants exist for a list, they can be offered
    to the user for selection. If a display variant is set as the default variant, the associated
    list is always displayed based on the settings of this variant.
    2. REUSE_ALV_LIST_DISPLAY
    REUSE_ALV_GRID_DISPLAY
    REUSE_ALV_FIELDCATALOG_MERGE
    REUSE_ALV_COMMENTARY_WRITE
    3. Use of Field Catalog is to determines the technical properties & add formating information of the column.
    6. all the definition of internal table, structure, constants are declared in a type-pool called SLIS.
    7.fieldcat-fieldname
    fieldcat-ref_fieldname
    fieldcat-tabname
    fieldcat-seltext_m
    5. Form user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield.
    Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length.
    In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output.
    The report output can contain up to 90 columns in the display with the wide array of display options.
    <b>The commonly used ALV functions used for this purpose are;</b>
    1. REUSE_ALV_VARIANT_DEFAULT_GET
    2. REUSE_ALV_VARIANT_F4
    3. REUSE_ALV_VARIANT_EXISTENCE
    4. REUSE_ALV_EVENTS_GET
    5. REUSE_ALV_COMMENTARY_WRITE
    6. REUSE_ALV_FIELDCATALOG_MERGE
    7. REUSE_ALV_LIST_DISPLAY
    8. REUSE_ALV_GRID_DISPLAY
    9. REUSE_ALV_POPUP_TO_SELECT
    Purpose of the above Functions are differ not all the functions are required in all the ALV Report.
    But either no.7 or No.8 is there in the Program.
    <b>
    How you call this function in your report?</b>
    After completion of all the data fetching from the database and append this data into an Internal Table. say I_ITAB.
    Then use follwing function module.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = 'Prog.name'
    I_STRUCTURE_NAME = 'I_ITAB'
    I_DEFAULT = 'X'
    I_SAVE = 'A'
    TABLES
    T_OUTTAB = I_ITAB.
    IF SY-SUBRC <> 0.
    WRITE: 'SY-SUBRC: ', SY-SUBRC .
    ENDIF.
    ENDFORM. " GET_FINAL_DATA
    The object F_IT_ALV has a field, the activity ACTVT, which can
    contain four permitted values: 01, 02, 03 and 70. Each of the
    activities 01, 02 and 70 controls the availability of particular
    functions (in the menu and the toolbar) of the ALV line item list:
    a) 01: "Settings -> Display variant -> Save..."
    b) 02: "Settings -> Display variant -> Current..." and
    "Settings -> Display variant -> Current header rows "
    c) 70: "Settings -> Display variant -> Administration..."
    Activity 03 corresponds to the minimum authorization, which is the
    most restricted one: The user can only select layouts which have
    been configured already. In particular, all of the other functions
    named above are inactive with activity 03.
    Now if you want to permit a user to change the column selection and
    the headers as well as to save the layout thus created, for example,
    but if you do not want to permit the user to administrate the
    layouts, you grant him or her the authorization for activities 01
    and 02.
    Check this link it will be mosty usefull for u
    http://www.sap-img.com/fu017.htm
    Reward all helpfull answers
    Regards
    Pavan

  • Hi, I've used four different Groups when emailing for the past few years, and suddenly they have stopped working. I've tried creating new Groups but that doesn't work either. I haven't changed or done anything different and it is driving me mad......

    Hi, I've used four different Groups when emailing for the past few years, and suddenly they have stopped working. I've tried creating new Groups but that doesn't work either. I haven't changed or done anything different and it is driving me mad......can anyone help, please?!

    Thanks for that information!
    I'm sure I will be calling AppleCare, but the problem is, they charge for the phone calls don't they? Because I don't have money to be spending to be on the phone with a support service.
    In other things, it seemed like the only time my MacBook was working was when I had Snow Leopard without the 10.6.8 update download that was supposed to be done to prepare for OS X Lion.
    When I look at the information of my HD it says that I have 10.6.8 but that was the install that it claimed to have failed and caused me to restart resulting in all of the repeated problems.
    Also, because my computer is currently down, and I've lost all files how would that effect the use of my iPhone? Because if it doesn't get fixed by the time OS 5 is released, how would I be able to upgrade?!

  • I have bought an iPhone4 and to be able to use it for the first time I connected into a friends itunes. Now when I want to buy itunes stuff on the phone it asks me her password. How can I set up again my itunes account?

    I have bought an iPhone4 and to be able to use it for the first time I connected into a friends' itunes. Now when I want to buy itunes stuff on the phone it asks me her password. How can I set up again my itunes account?
    Now I also have a macbook where I can sync my iphone but it doesn't allow me

    first of all only sync it with 1 computers itune account
    second settings->general->store click the appleID box with her appleID in it and log out

  • How can I use some of the image i am working on to paint with? like if I wanted to give someone an extra eye in the forehead, ow could i then paint their own i in the forehead? I know there is a paint tool for that, i just can't find it ... :/

    How can I use some of the image i am working on to paint with? like if I wanted to give someone an extra eye in the forehead, ow could i then paint their own i in the forehead? I know there is a paint tool for that, i just can't find it ... :/

    It sounds like you are talking about the cloning tool?
    Tool looks like this:
    Then when selected you can change the size of the brush and using Alt (windows) and Command (Mac) to select your region you want to copy then start to create you cloned image.
    Hope this helps?

  • How stop PS6 from removing the DPI value from an image when using "save for the web"?

    How stop PS6 from removing the DPI-value from an image when using "save for the web"?
    Example:
    - Open a tif image, that contains a dpi value (resolution).
    - Use the splice tool in PS6.
    - Export the slices with "Save for web", as gif-files.
    Then the dpi value is removed, the gif files has no dpi value (it's empty).
    How can we stop PS6 from removing the dpi value when using "save for web"?
    OR:
    When using the slice tool, how can we save the sliced pieces without PS removing the dpi value?

    you can make your art go a little bit over the bounds. or you can make sure your artboart and art edges align to pixels

  • How can I copy the titles from a project volume one use them for the rest?

    I'm editing a four DVD set, and would like to use the same opening titles and credits for each. How can I copy the titles from volume one and use them for the rest? Thank you.

    Open the project that has the titles you want to use. Select (highlight) all the title clips you want, then right-click and choose COPY.
    Open the new project(s), then paste the titles onto the Timeline.
    Done.
    -DH

  • How to provide security settings for the adobe form using livecycleDesigner

    Hello,
    I am very new to form designing,
    can any one please tell me how to provide security settings for the adobe forms at client side?
    Regards,
    Menaka

    Hi,
    that is a good topic for the ADFS forum.
    ADFS forum - http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=Geneva
    But you could pass the user-agent as incoming claim type Client User agent. User-agents can be manipulated, so if that is an issue you can look into Device Registration and the Device OS type from there. That is also a incoming claim but requires DRS and
    DRS is not available for all plattforms.
    Hth,
    Lutz

Maybe you are looking for

  • Late 2011 macbook pro a1278 no keyboard or trackpad

    LATE 2011 MBP a1278 , i5  , running Mountain Lion 10.8.5 Keyboard and Trackpad stopped working after a regular shut down with no peripherals attached or bluetooth on. Keyboard allows pram and smc reset before entering OS X environment . Only power bu

  • Fast refreshable mviews vs. cdc

    im currently working on a new data warehouse environment. i need to create an ods schema for each of the operational systems in my warehouse. i've looked at two of 10gR2 prefered technologies for this task: fast refreshable materialized view and chan

  • Purchase DVD Studio Pro 3

    I have DVDSP2 but would like to have DVDSP3 for the dual layer burning capability. I am still running OS 10.2.8 (Yeah, I know, but, "if it ain't broke don't fix it".) My Problem is I can't find an upgrade to DVDSP3. eBay has only 1 for $399 which is

  • ITunes Accounts - 1 account for multiple iPads?  Best Practices?

    I'm setting up a small deployment of 5 iPads for use in my company.  Could anyone share some tips / best practices as far as iTunes accounts are concerned? We would like to use one iTunes account to activate all of the iPads and set up / link to each

  • Safari for Windows - Downloading application problems

    Hi Everytime I try to download Safari for Windows all I get is a small file of 4k, called SafariSetup.exe. Seems to be an incomplete download.Tried on my MacBook and my PC same result. Is there a problem with the download? Tried in safari mac, opera,