limit the number of values in the listagg function and create several games

Hi all

I have a requirement where I would like to group one of the fields in a field based on the number of records. Lets say if we have an employee with multiple CODEZONE. Please see the example below. I want concatenation of each 10 EMPNO records into one. If she has more than 10 records for a given EMPNO, it should show in the form of another record.
For example:
EMPNO CODEZONE
A111 AL
A111 AK
A111 AZ
A111 AR
A111 CA
A111 CO
A111 CT
TO A111
A111 DC
A111 FL
A111 GA
A111 HI
B222 AL
B222 AK
B222 AZ
B222 AI
B222 KS
B222 KY
THE B222
B222 ME
B222 MD
MY B222
B222 MI
B222 CA
B222 CO
B222 CT
B222 OF

Result set:
EMPNO CODEZONE
A111 AL | AK | AZ | AR | CA | CO | CT | OF | DC | FL
A111 GA | HI
B222 AL | AK | AZ | AI | KS |     KY | THE | ME | MD | MY
B222 MI | CA | CO | CT | OF

The above example can have any number of area CODE for a given EMPNO, the end result should show only a maximum of 10 codes for an EMPNO in each record. If she has more than 10 CODEZONE, it should show as another record. Please provide me with a generic statement to solve this problem. I was not able to control by setting the limit on records for an EMPNO gave to the LISTAGG function. Any ideas are much appreciated.

Thank you

1008754 wrote:
Hi all

I have a requirement where I would like to group one of the fields in a field based on the number of records. Lets say if we have an employee with multiple CODEZONE. Please see the example below. I want concatenation of each 10 EMPNO records into one. If she has more than 10 records for a given EMPNO, it should show in the form of another record.
For example:
EMPNO CODEZONE
A111 AL
A111 AK
A111 AZ
A111 AR
A111 CA
A111 CO
A111 CT
TO A111
A111 DC
A111 FL
A111 GA
A111 HI
B222 AL
B222 AK
B222 AZ
B222 AI
B222 KS
B222 KY
THE B222
B222 ME
B222 MD
MY B222
B222 MI
B222 CA
B222 CO
B222 CT
B222 OF

Result set:
EMPNO CODEZONE
A111 AL | AK | AZ | AR | CA | CO | CT | OF | DC | FL
A111 GA | HI
B222 AL | AK | AZ | AI | KS |     KY | THE | ME | MD | MY
B222 MI | CA | CO | CT | OF

The above example can have any number of area CODE for a given EMPNO, the end result should show only a maximum of 10 codes for an EMPNO in each record. If she has more than 10 CODEZONE, it should show as another record. Please provide me with a generic statement to solve this problem. I was not able to control by setting the limit on records for an EMPNO gave to the LISTAGG function. Any ideas are much appreciated.

Thank you

ME_XE?with data (empno, areacode) as
  2  (
  3     select 'A111', 'AL' from dual union all
  4     select 'A111', 'AK' from dual union all
  5     select 'A111', 'AZ' from dual union all
  6     select 'A111', 'AR' from dual union all
  7     select 'A111', 'CA' from dual union all
  8     select 'A111', 'CO' from dual union all
  9     select 'A111', 'CT' from dual union all
 10     select 'A111', 'DE' from dual union all
 11     select 'A111', 'DC' from dual union all
 12     select 'A111', 'FL' from dual union all
 13     select 'A111', 'GA' from dual union all
 14     select 'A111', 'HI' from dual union all
 15     select 'B222', 'AL' from dual union all
 16     select 'B222', 'AK' from dual union all
 17     select 'B222', 'AZ' from dual union all
 18     select 'B222', 'IA' from dual union all
 19     select 'B222', 'KS' from dual union all
 20     select 'B222', 'KY' from dual union all
 21     select 'B222', 'LA' from dual union all
 22     select 'B222', 'ME' from dual union all
 23     select 'B222', 'MD' from dual union all
 24     select 'B222', 'MA' from dual union all
 25     select 'B222', 'MI' from dual union all
 26     select 'B222', 'CA' from dual union all
 27     select 'B222', 'CO' from dual union all
 28     select 'B222', 'CT' from dual union all
 29     select 'B222', 'DE' from dual
 30  )
 31  select
 32     empno, listagg(areacode, ',') within group (order by emp_grp)   as emp_list
 33  from
 34  (
 35     select
 36             ceil(row_number() over (partition by empno order by areacode) / 10) as emp_grp,
 37             empno,
 38             areacode
 39     from data
 40  )
 41  group by empno, emp_grp;

EMPNO                          EMP_LIST
------------------------------ ------------------------------
A111                           AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL
A111                           GA,HI
B222                           AK,AL,AZ,CA,CO,CT,DE,IA,KS,KY
B222                           LA,MA,MD,ME,MI

4 rows selected.

Elapsed: 00:00:00.05
ME_XE?

In the future, it would be nice if you could provide baseline data.

See you soon,.

Tags: Database

Similar Questions

  • I missed the SHIFT key and press several keys in the lower corner of my keyboard LH. Firefox split up into several iterations, and I had to reboot.

    I missed the SHIFT key and press several buttons in the lower left corner of my keyboard. Firefox has lost the tab that I was using and divided into a separate iteration for each other (plus two I had closed). I could not recover and had to close all but one of them and restore all my tabs.

    What I had done and how I should have recovered?

    First, you need to update to Firefox 18.0.1 Firefox updated to the latest version. The version you are on is bug and little course.

    Second, it looks like you may have entered groups of tabs. Use tab groups to organize a large number of tabs is that look familiar?

  • I use the random function and he know instructions 'case' must end with a ':' but it is!

    I use the random function and he know instructions 'case' must end with a ':' but it is! I put

    case 10000 timer += 2; popupName._visible = true; :

    then I put

    case of 10000 {timer += 2; popupName._visible = true ;}:}

    but he still know it.

    What I am doing wrong?

    First of all, whenever you have more than three similar lines, you should probably refactor something.  Especially when you have 10,000 lines. This should have sounded the alarm, but I guess you are new to this.

    Second, when you have such a long code, paste everything here. Please, I beg you. It's a pain to navigate the thread.

    And here's what I * think * you really want:

    If (random (10001) == 10000) {}

    timer += 2;

    popupName._visible = true;

    }

    It simply means: "take a random number between 0 and 10001 (exclusive). If this number is 10,000, do something. If not, ignore this code block. »

  • IPhoto on the external hard drive will not launch despite the force quit and relaunch several times. Can someone help me?

    I have a MacBook from 2008. 4 years ago I moved my iPhoto on an external hard drive. I have thousands if photos on it. IPhoto on the external hard drive will not launch despite the force quit and relaunch several times. Can someone help me?

    < re-titled by host >

    I moved my iPhoto on an external hard drive.

    Did you move the iPhoto library for the external hard drive or the iPhoto application, or both?

    How is formatted the external hard drive? Is the file system on the drive Mac OS extended (journaled) or other system files?  Is the drive directly connected by USB or similar, or is it a SIN?

    IPhoto on the external hard drive will not launch despite the force quit and relaunch several times.

    I don't understand - if you force quit smoking, launches the application, or you can not force it quit?

    IPhoto is suspended without doing anything, when you launch?

    What version of iPhoto does? And what version of Mac OS X?

  • Hello! I use a PC and have problems loading my homepage of Muse. First of all, I made one with the address "nordensstjarnor" and updated several times without any problems. And once, I couldn't download on 'nordensstjarnor' any longer. Don't know why, s

    Hello! I use a PC and have problems loading my homepage of Muse. First of all, I made one with the address "nordensstjarnor" and updated several times without any problems. And once, I couldn't download on 'nordensstjarnor' any longer. Don't know why, when he got the address "nordensstjrnor". That me ok at first, but now I really need to give the first address once again, "nordensstjarnor". But when I try, the alternative of the site of ' publish on ' old isn't here. And if I try to create a new one, but with the old URL, the box turns red. What can I do?

    The reason why you cannot change nordensstjarnor.businesscatalyst.com is because a different Adobe ID is used for the publication of this site.

    t * [email protected] is used for the publication of nordensstjarnor.businesscatalyst.com

    t s. * [email protected] is used for the publication of nordensstjarnorindex.businesscatalyst.com

    You must make sure that Adobe ID is used in account publish, so that you can see a list of the websites published under this account. Go in Edition > Preferences > publish on Business Catalyst > publish with accounts

    You can pass the accounts for you can also make changes to the sites.

    Thank you

    Sanjit

  • I have download a creative demo for the last month and created many documents on my computer now change my employer my where are my document or computer how can I get some how?  Thank you

    I have download a creative demonstration for the last month and created many documents on my computer

    Now, my employer just changed my computer where are my document or how can I get some how?

    Thank you

    they are still on the computer you were using (unless someone irretrievably erased).

  • Hi, I'm developing a simple mobile app in DW CC 2015 using JQuery Mobile. LIKE I need the list view with description of the product, functionality and image, I would like to connect with database instead of "writing" all the tables in the bearings inside

    Hi, I'm developing a simple mobile app in DW CC 2015 using JQuery Mobile. LIKE I need the list view with description of the product, functionality and image, I would like to connect with database instead of "writing" all the tables in the bearings inside the Jquery page. In the future I would also be able to add, to remove the DB records. Any help, tutorial... Thanks TG

    I would like to connect with the database instead of "writing" all the tables in the bearings inside the Jquery page

    This is usually done with a CMS (content management system). There are commercial products CMS like WordPress, Joomla and perch. You create one or several layouts and then create pages of these page layouts using the CMS. In this way, it is possible to have hundreds of pages, each with unique content, but a page layout that can be managed in a place of sharing.

    CMSs on shelf don't require programming skills. Otherwise, some of us write our own CMS with custom functions, but this requires back-end, as with PHP programming.

  • Capture the content of the pdf presentation and create a new document based on the data?

    Are there programs that can capture the content of the pdf presentation and create a new document based on that? I want to convert the data from a pdf form to fill in an auto-generated shipping label. Thank you!

    Only field names that match exactly. You can use JavaScript and hidden fields to match the names of domain if necessary.

  • Any difference between the separate function and aggregation in sql query cost?

    Hello
    I've run many models sql stmts - such as:
    one) using a single table
    (b) using the two tables, using simple joins or outer joins

    but I didn't notice a difference in sql stmts in cost and implementation plan...
    In any case, my colleague insists on only using the aggregate function is less expensive compared to
    separate... (something I've not confirmed, that is why I believe that they are exactly the same...)

    For the situation described above under 1 sql... We could for example use
    select distinct deptno
    from emp
    select count(*), deptno
    from emp
    group by deptno
    select distinct owner, object_type from all_objects
    select count(*), owner, object_type from all_objects
    group by owner, object_type
    Have you ever found no difference between the two...?

    Note: I use Ora DB 10g v2.

    Thank you
    SIM

    Alexandre Gelin says:
    function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...

    really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.

    article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
    This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf

  • Limit the control panel and IE for the Standard user account

    I'll set up a new computer for a 91 year old customer in a retirement home, who don't use the computer for e-mail and an occasional Wordpad document.  His son wants to put computer in place so that it cannot get to the Internet Explorer browser, or go to control panel, because he bumbles around the keyboard causing all sorts of problems requiring frequent service for me calls.

    The operating system is Windows Vista Home BASIC, so gpedit.msc is not installed.  I have activated the system administrator account for my use when I am called to repair the computer and set the Standard user to user account.  The problem is that the only way I found to disable IE and the Control Panel causes them be turned off in BOTH accounts.  I wish I could disable them ONLY in the user account.

    The only solution I found to disable the control panel is a registry hack in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current versionpolicies where I put a DWORD 32-bit "NoControlPanel" with a value of 1.  I tried to do that in the HKEY_CURRENT_USER hive, but it had no effect.  This kind of work, but there are two problems then; Mises_a_jour Windows 1) won't install and 2) when I have to go to work on the computer, I first change administrator user, then change the DWORD value to 0 and finally to restart the computer, causing additional assignments, lengthen my time at work.

    Second, the only solution I could find to disable IE was in the default protrams Panel, which disables the administrator as well.

    Can someone tell me if there is another way to achieve this, while IE and control panel are disabled only for the user?

    Change the security to the IE executable rights? Remove 'Users', while you keep the administrator rights.

    For control panel see 'Method Two' in this link:

    http://www.Vistax64.com/tutorials/120951-Control-Panel-show-specific-icons-only.html

    "creacontech" wrote in the new message: * e-mail address is removed from the privacy... *

    Thanks for your response, but will not solve problem of this "gentleman". The object is not so much to limit internet access, as it should restrict access to programs.  He is 91 years old, has small hands and types rapidly with two fingers, but made many mistakes.  Disability is before everything to prevent clikety snap everywhere, because he creates sort of a zillion copies shortcuts of the webpage on his desk, until everything hangs and I have to go a push up on his mess. The same reason applies to the Contorl Panel.  We don't want it to be able to get to the Panel "printers."  When a document will not be printed for a reason, he go, dummy click around and created a bunch of copies of the printer, with a gazillian of documents clogged up in the queue of the coil.  I had to cclear up to 100 documents from the spool on 50 copies printer queue.  It's really an economic problem for his son.

  • Need help with the listagg function

    Hi all

    I try to use Listagg in the query below, but not able to get the answer. It is throwing an error message saying ORA-00979: not a GROUP BY expression.

    If I try to remove the Group By function and run the query, I get the following error ORA-00937: not a function of simple-group.

    Help, please.

    Select Distinct V.User_X, V.Original_Request_Id, (V.Support_Group_Name, ',') listagg Group (order of V.Support_group_name) as Group1,

    T.Individualassignedto, T.Status, T.Groupassignedto, T.Ticketcategory, T.Tickettype, T.orgcompany, T.submitter,

    T.Orgassignedto, T.Urgency

    Display V

    INNER JOIN K_TICKET T ON T.TICKETNUMBER = V.ORIGINAL_REQUEST_ID

    V.Original_Request_ID group

    Because you use a GROUP BY, you don't need SEPARATE.

    All the columns you are not aggregate (list) should be in the GROUP BY.

  • Bug with the aggregate function and no group

    When I run the following query:
    with the_table as
    (
      select 1 as id, 100 as cost from dual
      union all select 2 as id, 200 as cost from dual
      union all select 3 as id, 300 as cost from dual
      union all select 4 as id, 400 as cost from dual
      union all select 5 as id, 500 as cost from dual
    )
    select id, cost
    from
    (
      select id, cost
      from the_table
      --
      union all
      --
      select 0 as id, sum(cost) as cost
      from the_table
      where 0 = 1
      -- group by 1
    )
    order by id;
    I get this result:
    ID    COST
    --  ------
     0  <null>     
     1     100
     2     200
     3     300
     4     400
     5     500
    However, when I "uncomment" the line "Group 1", the query works as expected (without the id = rank 0).

    This occurs even when "the_table" is an array.

    Someone else comes through this (and if so, how long is a problem)?

    The database is 11.2.0.2.0 64-bit.

    EDIT: It also happens without a Union - the following returns a single line (with null 0 and cost of id) without the Group By and no line with her:
    select id, cost
    from
    (
      select 0 as id, sum(cost) as cost
      from 
      (
        select 1 as id, 100 as cost from dual
        union all select 2 as id, 200 as cost from dual
        union all select 3 as id, 300 as cost from dual
        union all select 4 as id, 400 as cost from dual
        union all select 5 as id, 500 as cost from dual
      )
      where 0 = 1
      -- group by 1
    )
    order by id
    Edited by: Donbot February 15, 2012 10:29

    Donbot wrote:
    Someone else comes through this (and if so, how long is a problem)?

    The database is 11.2.0.2.0 64-bit.

    This is a documented behavior.

    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions003.htm#SQLRF20035

    "
    All except COUNT (*) GROUPING and GROUPING_ID aggregate functions ignore NULL values. You can use the NVL function in the argument of an aggregation function to substitute a value for a null value. COUNTY and REGR_COUNT never return null, but return a number or zero. For all remaining functions of aggregation, * if the DataSet contains no line, * or if it contains only the rows with NULL values as arguments to the aggregate function, * then the function returns null.*
    "

  • Problems with the sound function and scrolling on the touchpad on my Satellite A500/026

    Hello

    I just brought a new laptop A500/026 and when I play music from my ipod I get a little static pop sound at regular intervals during the song... this happens on all my music. I accidentally scroll horizontally through my touhpad and my screen minimizes or maximizes. I try to find how I did it, but can never seem to return to its normal state. There is obviously some sort of function here, can someone help me with it? I installed the x 64 bit version of windows 7.

    Thank you

    Eddie

    Hello

    The touchpad settings are placed in Control Panel-> mouse
    You can find the additional tab which would be you can access touchpad properties.

    As I know the touchpad properties contains many different options that allows you to configure the scrolling function, to activate and assign different actions to the touchpad corners, etc.

    Check it!

  • Satellite L500-19 - remove the recovery partition and create new

    Hello!

    I bought a new Toshiba Satellite L500-19th with Windows 7 Home Premium (64-bit). So far, everything is brilliant work.
    I have already created the recovery DVDs.
    As a result, could now delete the partition with the recovery program? I want to use the full space of my hard disk and create partitions as I want.
    But I don't know how I should do this?
    Could you please help me?

    Oxford

    If you are sure that the created recovery DVD is ok at 100%, you can delete all data on the second partition.
    Open Windows Explorer on the left side where is the second partition, click with the right button of the mouse and choose the FORMAT option.
    Choose the quick format option and click START.

    After a minute or two, all data will be gone.

    Please note: in the future when you want to use recovery DVD for installing Win7 the whole HARD disk is deleted and you will lose all your data.
    Using recovery DVD you can not format the C partition only.

  • The single video stream creating several necessary video effect.

    I created a video wall to serve as a backdrop for a staging. The wall is made up of 8 screens of television randomly spaced 55 ". I used Videoplex4 to black box to stretch the video image to feed on all eight monitors to create a single video image. However, I need a program that will allow me to create a model that mimics my wall of monitors so that I can drop video segments in the model, creating the effect that I have 8 simultaneous video streams. Then, I need to be able to "cue" various video clips during a twenty minute show, so they sync with the live action on stage. Please notify the necessary software and hardware in the way of what I need to pull this off.

    Thank you

    I used Videoplex4 to black box to stretch the video image feed

    on all eight monitors to create a single video image.

    What is the resolution of the "flow video image" used by the "Videoplex4 of the black box?"

    However, I need a program that will allow me to create a model that mimics

    my wall of monitors so that I can drop video segments in the model

    creating the effect that I have 8 simultaneous video streams.

    This can be done by first using several layers and effects of "picture-in-picture.

    in a sequence that is defined in the format you plan to "Videoplex4 of the black box."

    but it will take a few tries to have the images where they will be

    correctly positioned once powered through "black box Videoplex4.

    Then, I need to be able to "cue" various video in clips

    20 minutes show so that they synchronize with the live action on stage.

    Yes, there is the problem... I don't know how with clues "on-line".

    Not knowing your content planned or how does the 'Videoplex4 of the black box. "

    It is difficult to propose things like the closure of the readings or gels that can be added.

    or instantly accessible searchable index points in reading.

    It would be much more practical to produce the video, so that the company

    Use it in their rehearsals for the performance of the existing time video

    instead of trying to time the video in a real context to the artists on stage.

Maybe you are looking for