Limit the number of values in the listagg function and create multiple sets

Hi All,
I have a requirement where I would like to group one of the fields into one field based on the number of records. Lets say if we have an employee having multiple AREACODE's. Please see the below example. I want to do string concatenation of every 10 records of EMPNO into one set. If it has more than 10 records for a given EMPNO, it has to display as another record.
Eg:
EMPNO AREACODE
A111     AL
A111     AK
A111     AZ
A111     AR
A111     CA
A111     CO
A111     CT
A111     DE
A111     DC
A111     FL
A111     GA
A111     HI
B222     AL
B222     AK
B222     AZ
B222     IA
B222     KS
B222     KY
B222     LA
B222     ME
B222     MD
B222     MA
B222     MI
B222     CA
B222     CO
B222     CT
B222     DE
Result Set:
EMPNO AREACODE
A111     AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL
A111     GA|HI
B222     AL|AK|AZ|IA|KS|     KY|LA|ME|MD|MA
B222     MI|CA|CO|CT|DE
The above example can have any number of AREACODE's for a given EMPNO, final result should display only a maximum 10 area codes for a given EMPNO in each record. If it has more than 10 AREACODE's it should display as another record. Please provide me a generic query to solve this. I was not able to control by setting the limit on the records for a given EMPNO on to LISTAGG function. Any ideas are highly appreciated.
Thanks

1008754 wrote:
Hi All,
I have a requirement where I would like to group one of the fields into one field based on the number of records. Lets say if we have an employee having multiple AREACODE's. Please see the below example. I want to do string concatenation of every 10 records of EMPNO into one set. If it has more than 10 records for a given EMPNO, it has to display as another record.
Eg:
EMPNO AREACODE
A111     AL
A111     AK
A111     AZ
A111     AR
A111     CA
A111     CO
A111     CT
A111     DE
A111     DC
A111     FL
A111     GA
A111     HI
B222     AL
B222     AK
B222     AZ
B222     IA
B222     KS
B222     KY
B222     LA
B222     ME
B222     MD
B222     MA
B222     MI
B222     CA
B222     CO
B222     CT
B222     DE
Result Set:
EMPNO AREACODE
A111     AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL
A111     GA|HI
B222     AL|AK|AZ|IA|KS|     KY|LA|ME|MD|MA
B222     MI|CA|CO|CT|DE
The above example can have any number of AREACODE's for a given EMPNO, final result should display only a maximum 10 area codes for a given EMPNO in each record. If it has more than 10 AREACODE's it should display as another record. Please provide me a generic query to solve this. I was not able to control by setting the limit on the records for a given EMPNO on to LISTAGG function. Any ideas are highly appreciated.
Thanks
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 the starting data.
Cheers,

Similar Messages

  • The Domain file and creating multiple ULR's

    I've notice that the question comes up about publishing multiple sites from one MobileMe iWeb account. My question is this, as you have only one Domain file, to achieve publishing more than one site does this mean you create and publish site A, then back it up and remove this Domain file, then create a second site B, publish and backup and so on. Replacing the appropriate Domain file to make changes and republishing the changes.
    My interest is that my site is now around a hundred plus pages in length and it might be an option to subdivide them into several linked elements.
    If you have any thoughts or experience of creating multiple sites in iWeb that are in structure straight up and down with not too many curves I'd be very interested to hear about your experiences.

    You can easily create multiple sites with one MMe account.
    Yes, you have one domain file, but what you need to do is duplicate that domain file, so that you have one site per a domain file. Either this, or use the program iWebSites to help you organise multiple sites within iWeb.

  • Trying to fetch a value in a java function and returning the array.

    hello....I am trying to fetch a value in a java function and returning a array......I already write the pl/sql function which is working fine....but i think i m lost......when i run it through the jsp it shows me error........pls help
    java code:=
    public String [] viewx(String bid) throws SQLException, Exception {
    String [] values;
    try {
    CallableStatement cstmt = null;
    String SQL = "{?=call vi_dis.v_dis(?)}";
    cstmt = con.prepareCall(SQL);
    cstmt.registerOutParameter(1,Types.ARRAY);
    cstmt.setString(2, bid);
    cstmt.execute();
    Array simpleArray = cstmt.getArray(1);
    values = (String [])simpleArray.getArray();
    cstmt.close();
    } catch (SQLException sqle) {
    error = "SQLException: Could not execute the query.";
    throw new SQLException(error);
    } catch (Exception e) {
    error = "An exception occured while retrieving emp.";
    throw new Exception(error);
    return values;
    pl/sql function
    create or replace package vi_dis
    as
    function v_dis(vbid IN student.bid%type) return stuarray ;
    end;
    create or replace
    package body vi_dis
    as
    function v_dis(vbid IN student.bid%type) return stuarray
    is
    l_stu stUarray :=stuarray();
    cursor c_sel
    is
    SELECT CNAME
    FROM COURSE C,ENROLL E
    WHERE C.CID=E.CID
    AND E.BID=vbid;
    BEGIN
    OPEN c_sel;
    FETCH c_sel BULK COLLECT INTO l_stu;
    l_stu.extend;
    CLOSE c_sel;
    RETURN l_stu;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN DBMS_OUTPUT.PUT_LINE('NO RESULT AVAILABLE');
    CLOSE c_sel;
    END;
    END;
    /

    BalusC wrote:
    It is comparing the selected value against the List<SelectItem> returned by getSetoresOrigem() as it is during the apply request values phase of the form submit request.Ok. That's what I supposed JSF was doing.
    BalusC wrote:
    If the selected value isn't in there, then you will get this error.I can understand this, but is this right? As I said, the old value isn't really there because I changed the list values to new ones. But the new value (the value of fSetorOrigem ) corresponds to a value that exist in the new list items, so a valid value. So JSF is not considering that I also changed the list, not just the value. It is comparing the new value with the old list, not the new one. Acting like this JSF is making the page looks like a static HTML page, not a dynamic one. If I can't change the list and the value, what's the point of that? In my point of view I'm not doing anything wrong, I'm not violating any JSF rules.
    Marcos

  • Can I limit the padding of a field (Multiple Selection) ?

    I am creating a form in FORMCENTRAL. Can I limit the padding of a field (Multiple Selection) ?

    Hi;
    You can adjust the size of the outer dotted line surrounding the field from the right side which will reduce the padding.  For most of the field types you can adjust the size of the input box, and also the size of the overall field which controls the amount of padding (to the right, can't control top/bottom or left).
    Thanks,
    Josh

  • My husband and I have upgraded our phones (iPhone 4s and iPhone 5) to the iPhone 5s.  We have given 2 of our kids the "old" phones and want to set them up as an iPod touch.  Both kids have email and need to be able to text (iMessage).

    My husband and I have upgraded our phones (iPhone 4s and iPhone 5) to the iPhone 5s.  We have given 2 of our kids the "old" phones and want to set them up as an iPod touch.  Both kids have email and need to be able to text (iMessage).
    I have read multiple posts on how to do this and I am still confused.
    Apple ID/ICoud:
    We want to be able to monitor what they do, but do not want their devices linked to our emails/contacts/etc...  Each kid has their own email account.  So, from what I have read the best way to do this is to use our family Apple ID, but set them up with a separate iCloud account?  Is this correct?
    Reset/Restore/DFU:
    To start fresh we have done multiple factory resets.  I did one that someone said was a DFU and a plan ol' factory reset, etc...  Not sure the difference.  However, when I do that I get the "hello" screen and am able to start setting the phone up anew.  However, when I go to set the phone up as an iPod I end with the same result.
    So, here is what I am doing (tell me what I am doing wrong):
    Hello Screen
    Asks me to select language and selecting:  English
    Select Your Country or Region:  United States
    Choose a Wi-Fi Network:  select my home wi-fi network
    Enter password:  entered my home wi-fi network password
    Activiate iPhone - wants me to enter Apple ID and Passwordsays that this iphone is currently linked to an Apple ID (k*******@gmail.com).  Sign in with the Apple ID that was used to set up this iPhone.
    Location Services - I have enabled location services
    Set Up iPhone
    Set Up as New iPhone
    Apple ID
    Options are to sign in with your Apple ID or Create a Free Apple ID
    Or I could "skip this step"
    I signed in with my Apple ID
    Terms and Conditions - Agree
    iCloud - I can select either to use iCloud or Don't Use iCloud - I selected use iCloud
    Find My iPhone - I can select either to use find my iPhone or to not - I selected use find my iphone
    Once I do this it says iMessage and FaceTime and shows the following:
    my email
    my other child's cell phone number
    and my husband's work phone number
    This is where things do not make sense.  I only want the phone set up with the current child's email address.  Where did I go wrong?

    There are a number of Apple services: iMessage, FaceTime, iCloud, Game center, Find My iPad, etc.
    Now, to share apps, music and books you need to have the same Apple ID:
    iPad's Settings > iTunes & App Stores > Apple ID > Your purchasing Apple ID.
    For the other service, your wife should have her own Apple ID.
    All she needs is a valid e-mail address, apply Apple ID below:
    https://appleid.apple.com
    Here's a limk with useful tips: Note: It's also valid in IOS 6
    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • I don't know how to use the canlendars function and the notes are kind of messy code,anyone help me

    i don't know how to use the canlendars function and the notes are kind of messy code,anyone help me

    Step by step:
    1. On your main vi Front Panel, create your boolean indicator.
    2. On the block diagram, right click the new boolean indicator and select Create - Reference.
    3. On sub-vi front panel, create boolean indicator (or use one that is already created).
    4. On sub-vi front panel, create a reference (Controls Palette - Refnum - Control Refnum).
    5. Right click on the newly created Refnum and select Select Vi Server Class - Generic - GObject - Control - Boolean. The refnum label changes to BoolRefnum.
    6. On sub-vi block diagram, create Property Node (Functions - Application Control - Property Node). Find the BoolRefnum and move it close to the new Property Node.
    7. Wire the BoolRefnum to the reference input of the property node.
    8.
    Right click on the property node and select Change to All Write.
    9. Move mouse to point to Visible inside property node box, left click and select Value.
    10. Wire the boolean indicator from step 3 to the Value input of the property node.
    11. On sub-vi front panel, right click on icon and select Show Connector.
    12. Click on empty connector spot then click on the new BoolRefnum. Save your sub-vi.
    13. On main vi block diagram, connect refernece created in step 2 to the new connector terminal of sub-vi.
    14. Save and run.
    Here are the modified vi's.
    - tbob
    Inventor of the WORM Global
    Attachments:
    Pass_a_Reference.vi ‏20 KB
    GL_Flicker_mod.vi ‏83 KB

  • I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have reduced functionality what it this about and how do I get my product back

    I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have reduced functionality what it this about and how do I get my product back

    Hi there
    I have version 5.7 and every time I opened it I was told that updates are available and to click on the icon to access these.  Instead it just took me to the
    adobe page with nowhere visible to update.  I then  sought to download lightroom cc and this is when I could not access the 'develop' section due to reduced
    functionality  It was apparent that my photos had been put in cc but no way to access them unless I wanted to subscribe. 
    I have since remedied the problem as  my original lightroom 5.7 icon is still available on the desktop and have gone back to that.  I do feel that this is a bit
    of a rip off and an unnecessary waste of my time though.
    Thank you for your prompt reply by the way.
    Carlo
    Message Received: May 04 2015, 04:52 PM
    From: "dj_paige" <[email protected]>
    To: "Carlo Bragagnolo" <[email protected]>
    Cc:
    Subject:  I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have
    reduced functionality what it this about and how do I get my product back
    dj_paige  created the discussion
    "I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have reduced functionality what it
    this about and how do I get my product back"
    To view the discussion, visit: https://forums.adobe.com/message/7510559#7510559
    >

  • Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Hi connally25,
    Below is a link to a video tutorial on how to add a Facebook Log button, please check if you have followed the same steps to add the video.
    http://tv.adobe.com/watch/learn-adobe-muse-cc/adding-a-facebook-like-button/
    If you have followed the steps correctly and the button still does not work; here is a link to a forum thread which might help solving the issue:
    Facebook Follow Widget not working
    Regards
    Sonam

  • Good Morning.  I'm having a problem using both my Photoshop elements and premiere programs.  I've installed the programs, redeemed my code and entered the serial numbers, and created the adobe log-in.  I am able to open up the organizer without problems,

    Good Morning.  I'm having a problem using both my Photoshop elements and premiere programs.  I've installed the programs, redeemed my code and entered the serial numbers, and created the adobe log-in.  I am able to open up the organizer without problems, but when I try to open up the photo editor (either by trying to open up the program from the main menu, or right-clicking on a photo in the organizer to edit in elements), the program asks me to sign in to adobe (which I can do and it doesn't give an an "incorrect password" or log-in ID error) then accept the terms and conditions.  When I click to accept the terms and conditions, nothing happens and the editor fails to open.  Everytime I click on the program, I get this same "loop" of signing in and accepting T&C's, but the program fails to open.  Any advice?

      Premiere Elements 10 is now 64 bit, but not PSE10.
    Take a look at your scratch disk set-up and if you have a spare volume, allocate that first before the C drive. Elements use scratch disks when it gets low on RAM.
    Click image to enlarge
    Turn off face recognition and the auto-analyzer to improve performance.
    When editing photos or videos check the task manager to see what background processes may be running and end them temporarily if not needed.

  • Custom Image Capture that Auto Imports the OS WIM and Creates a New Task Sequence

    We just finished a consulting project where our customer requested an easy solution to capture thick images.  After hearing their reasoning it made sense for their circumstances.  The people that
    will be managing the system will be non-technical and all they wanted was a very, very simple method of capturing and deploying images with no learning curve.   They wanted the ability to Deploy the images via PXE.  
    This quickly became both our easiest scope project but making MDT simple for non-technical users can be challenging.   The MDT capture and staging steps are pretty easy for tech savvy person but for non-technical people it presented a learning
    curve that the customer wanted simplified. They didn’t want to understand sysprep, capture, importing an OS and then creating a Task Sequence to reference that new image.        
    So we changed the scope of our project to automate MDT to perform additional steps following the capture that would:
    Automatically Import the Captured OS into the MDT Deployment Share
    Automatically Create a new Task Sequence that references the newly imported image
    Auto Name the Task Sequence with the Model Name, Date and Time of Capture
    The Final Solution:
    Customer will setup a Windows PC Thick Image (All software and drivers)
    The customer will Kick-off the Sysprep and Capture Task Sequence
    The customized Task Sequence will capture, import the new image, and create a new TS with the new image
    Customer can then PXE boot a new computer and Deploy the image or stage to media and deploy the image
    We were able to remove the import OS and create new task sequence steps and this simplified it for our customer considerably.  If anyone is interested in this functionality
    let me know and I can send you instructions.  We used Vbscript, Powershell and PSExec.exe from PowerShell.  It seems to being working pretty good so far
    MDT Task Sequence Duplicator https://panaconsulting.egnyte.com/h-s/20130614/61707be809944999 Application Bundle Duplicator https://panaconsulting.egnyte.com/h-s/20130614/405e7d64e5d54610

    We just finished a consulting project where our customer requested an easy solution to capture thick images.  After hearing their reasoning it made sense for their circumstances.  The people that
    will be managing the system will be non-technical and all they wanted was a very, very simple method of capturing and deploying images with no learning curve.   They wanted the ability to Deploy the images via PXE.  
    This quickly became both our easiest scope project but making MDT simple for non-technical users can be challenging.   The MDT capture and staging steps are pretty easy for tech savvy person but for non-technical people it presented a learning
    curve that the customer wanted simplified. They didn’t want to understand sysprep, capture, importing an OS and then creating a Task Sequence to reference that new image.        
    So we changed the scope of our project to automate MDT to perform additional steps following the capture that would:
    Automatically Import the Captured OS into the MDT Deployment Share
    Automatically Create a new Task Sequence that references the newly imported image
    Auto Name the Task Sequence with the Model Name, Date and Time of Capture
    The Final Solution:
    Customer will setup a Windows PC Thick Image (All software and drivers)
    The customer will Kick-off the Sysprep and Capture Task Sequence
    The customized Task Sequence will capture, import the new image, and create a new TS with the new image
    Customer can then PXE boot a new computer and Deploy the image or stage to media and deploy the image
    We were able to remove the import OS and create new task sequence steps and this simplified it for our customer considerably.  If anyone is interested in this functionality
    let me know and I can send you instructions.  We used Vbscript, Powershell and PSExec.exe from PowerShell.  It seems to being working pretty good so far
    MDT Task Sequence Duplicator https://panaconsulting.egnyte.com/h-s/20130614/61707be809944999 Application Bundle Duplicator https://panaconsulting.egnyte.com/h-s/20130614/405e7d64e5d54610
    I would love to get the instructions to this process, as I have a simular client.

  • Can the interface menus and icons be set a little larger in 64bit Photoshop version CS6 ????

    Can the interface menus and icons be set a little larger in 64bit Photoshop version CS6 ????
    It would be very helpful if the tools and font size choices were enhanced to Larger, Largest or custom enhance. Anyone know if that is an idea we can send to Adobe?

    I wonder about folk who use small screen laptops with a high pixel density. I'd guess that there are 1920x1200 laptops with 17 or possibly even 15 inch screens, and Photoshop is going to be a nightmare to use on them. Heck, the notebook sized iPad 3 has a >2000 pixel screen! That sort of pixel density is going to work its way through to laptops, before too long. I have read about LED televisions with 4K (equivalent of four 1080 panels) and even 8K (equivalent of 8 1080 panels) screens. Is that going to work its way through to computer monitors? To be fair, we are talking about 60inch screens here, but nothing surprises me anymore when it comes to gamers and their hardware!!!
    I have all but given up using Photoshop on my 19 inch laptop with a 1920x1200 screen because it is not comfortable compared with the 30 inch monitor I use for my main screen at home (also 1920 x 1200). This is a frequently asked question, and Chris has said it would be a major undertaking to upsize the icons, but it surely has to go on the list for the next upgrade.

  • My external speakers have stopped working. A circle with a line through it shows up when I try to adjust the volume.  I have been in system prefrences to check all the sound settings and everything is set properly.  What do I need to do to fix this. Help!

    My external speakers have stopped working. A circle with a line through it shows up when I try to adjust the volume.  I have been in system prefrences to check all the sound settings and everything is set properly.  What do I need to do to fix this. Help!

    Though I have doubts for success, you might try a SMC reset.  It can do no harm.  Otherwise, barring suggestions from others, the Apple Store or qualified repair facility is the last option.
    http://support.apple.com/kb/HT3964
    Ciao.

  • The search function and up next option on mini player has dissapeared?

    I don't know what I've clicked, or maybe not touched anything but in the last few weeks the search function and up next playlist has disappeared on the mini player. I'm using OS Mavericks, anyone else having this problem or know what to do? Thanks

    With the exception of the occasional Russian and German questions that appear here... If the manual is written in English, and the questions posted here are predominantly written in English, I'm not convinced that language is therefore the problem.
    I think it kind of works like this... When newbs come here, they:
    1) have no prior experience to realize how often a similar question's been posted
    2a) aren't familiar with the "etiquette" of searching for similar questions befor posting
    2b) aren't familiar the lameness of the search engine on this forum in order to even get answers; or, they've tried it and come up with years' worth of posts to sift through and quickly move to...
    3) ...posting a question because they want a quick fix -- they're probably excited about getting up and running quickly with Logic
    I have always had problems with the readability of the Logic manual, and I still find it difficult to comprehend because it's really poorly written (IMO). Most, sentences in, it read, like, this. And there's a wont of illustrations (pictures are worth...).
    I think some questions are so basic that they don't behoove a response moreso than "spend some time with the manual first". Occasionally I've indulged a total newb (not to single anyone out). It's maybe 75/25 that I felt like I had actually made a difference to their understanding, the poor ratio due to the fact that they simply needed to read the manual first.
    Yes, it's frustrating to see newb posts dominate for a while and push more serious questions to the bottom. The occasional OT post is OK, IMO, but what bugs me more is when they predominate.
    BTW, can anyone recommend some good strings for a 3-string backpack-style dulcimer?
    : ^ )

  • What is the difference between "create set" and "create dynamic set"?

    What is the difference between  "create set" and "create dynamic set"?
    we have a complete cube ready for production that was tested and working without any issues in non-r2. we found that some "create set" assignments don't work in R2. But when changed to from  "create set" to "create dynamic set"?
    they are working, However, not sure how it will impact other areas of the cube.

    Thanks YuliaKlimov, I can reproduce this issue, but I cannot explain the different behaviors between SSAS 2008 and 2008R2. As a workaround,
    could you try to use dynamic set or create statics set but with fixed member for example:
    CREATE 
    SET CURRENTCUBE.[Prior Month] AS
    [Date].[Date Key].&[20050723].PrevMember
    , DISPLAY_FOLDER = 'Relative Period Sets';
    Personally, I think your set is dynamic set, because the currentmember is changed base on current selection. You can also submit this issue
    on below official link to get confirmation from Product Group:
     https://connect.microsoft.com/SQLServer/
    Thanks,
    Raymond
    Raymond Li - MSFT

  • Can I disable the wireless functionality and use Ethernet only?

    Can you completely disable the wireless functionality and use the Airport Extreme Base Station as a wired internet router with integrated print server?

    Yes. I do that. I don't use a print server but I was using that port for an HD. My AExpress connected to it is wired also.

Maybe you are looking for