Question: Pulling chunks of record by specifying percentage (%)

Before I upload a sample of the data I was wondering if someone could answer a question for me so I know whether it is possible.
Let’s say I have a column with bunch of IDs and another column with their age.
Is there a query which allows you to define your data by %
Eg. I want to pull 200 IDs.
Out of those I want 30% aged 18 - 29; 40% aged 30 - 39; 30% aged 40 - 50
Possible?
Using:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi

Chloe_19 wrote:
IF I wanted to make it 50% male 50% female out of the 200, how and where would I add that in your code?Do you mean in each age group or just by gender? In each age group:
WITH t AS (
           SELECT  id,
                   age,
                   gender,
                   case
                     when age <= 29 then '18 - 29'
                     when age <= 39 then '30 - 39'
                     else '40 - 50'
                   end age_group,
                   row_number() over(
                                     partition by case
                                                    when age <= 29 then '18 - 29'
                                                    when age <= 39 then '30 - 39'
                                                    else '40 - 50'
                                                  end,
                                                  gender
                                     order by id
                                    ) rn
             FROM  table_name
             WHERE age between 18 and 50
SELECT  id,
        age
  FROM  t
  WHERE (age_group = '18 - 29' AND gender = 'M' AND rn <= 200 * 0.3 / 2)
     OR (age_group = '18 - 29' AND gender = 'F' AND rn <= 200 * 0.3 / 2)
     OR (age_group = '30 - 39' AND gender = 'M' AND rn <= 200 * 0.4 / 2)
     OR (age_group = '30 - 39' AND gender = 'F' AND rn <= 200 * 0.4 / 2)
     OR (age_group = '40 - 50' AND gender = 'M' AND rn <= 200 * 0.3 / 2)
     OR (age_group = '40 - 50' AND gender = 'F' AND rn <= 200 * 0.3 / 2)
/Just by gender:
WITH t AS (
           SELECT  id,
                   age,
                   gender,
                   row_number() over(
                                     partition gender
                                     order by id
                                    ) rn
             FROM  table_name
             WHERE age between 18 and 50
SELECT  id,
        age
  FROM  t
  WHERE (gender = 'M' AND rn <= 200 / 2)
     OR (gender = 'F' AND rn <= 200 / 2)
/SY.

Similar Messages

  • Pulling out two records at a time

    I have a TABLE with multiple records in it, of which i want to pull out two records at a time (as if they were one record), of those records that meet the WHERE criteria. Order is not important. Basically, i have a TABLE of things that wither need processing or have been processed already. I can process two at a time. (In a related search, that i am not up to yet, i can do 20 at a time.) How would i go about doing that?
    My first thought was a CTE with ROW_NUMBER() RN, using CONNECT BY RN = PRIOR RN + 2, and have a sub-query (or joined TABLE) pull out the second record:
    WITH Moo (SELECT ... ROW_NUMBER RN FROM Table WHERE ...)
    SELECT ..., (SELECT ... FROM FROM Moo Moo2 WHERE Moo2.Id = Moo.Id + 1)
    FROM Moo CONNECT BY Id = PRIOR Id + 2;
    Or a join. Is there a better way to approach it?

    Pretty much everything you just said is wrong.
    >
    I generally keep away from CURSORs, as i want the DB to handle the set processing for me, as opposed to a CURSOR which tells the DB how to do it's job.
    >
    If you do any DB queries then you are using cursors. You have the wrong idea about them. All result sets are obtained using a cursor. A cursor does NOT tell a DB how to do a job; that is what the query and execution plan do.
    >
    (And, Tom Kyt's mantra of "You should do it in a single SQL statement if at all possible") But that's just a rule of thumb.
    >
    No - that isn't a rule of thumb. That is exactly what you should do if possible which is what I said. But I also said
    >
    Well the general use is to use SQL instead of PL/SQL but since you already need to use a function you might as well make that function as efficient as possible.
    >
    If you are already using a function then you should get the most bang for the buck from it and make it as efficient as possible.
    >
    If the CURSOR is the most efficient, so be it. But as you point out, if i'm already going to use a CURSOR, i might as well do all the work in the CURSOR LOOP. Why bother switching contexts.
    >
    All queries are done using cursors. It isn't a question of whether they are more efficient; it is the only way possible. I think you are referring to a user creating an explicit cursor and performing explicit manipulation of that cursor. That isn't normally what you want to do.
    A cursor loop is the slowest way to process results especially if all you are doing is row-by-row processing to perform essentially SQL-related work. PL/SQL should be used for the transactional part of the processing. In your case that transactional use is consolidating two records together for specialized processing.
    As for context switches if you perform any PL/SQL you are going to have a context switch: functions, procedures, triggers. The function you already planned to use would have caused a context switch. What I am saying is that if you are going to perform a context switch then you want to maximize the amount of work (transactional work) done in the PL/SQL engine so that you minimize the context switching.
    You still haven't explained exactly why 2 records at a time is any more ideal than 1 or if you could also process 50, 100, or 10000 at a time. Is the limit what needs to be passed somewhere else? What is the reason for a max of two? What exactly are you doing with the data to prepare it before you have to pass it on?
    Bulk collect processing is more efficient, with fewer context switches, if you process 20, 50, or 100 records in the loop at a time.
    See Chap 13 Using Pipelined and parallel Table Functions in the Data Cartridge Dev Guide
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28425/pipe_paral_tbl.htm

  • Changing Vendor Master Record to specify payment method

    Hi
    May I ask, how can we change the vendor master record to specify payment method.  I would like to choose automatic payment processing for my vendor.
    I am using T. Code XK-02, but where can we specify the payment method.  Please assist.
    Thanks
    Mohit

    Execute XK02 &
    Go to  payment transaction screen( tab) in that you have Automati payment transaction segment , under that you find the Payment method fIeld.
    here you can goiive the  payment method you want.
    chandra

  • How can I trap the question 'Could not reserve record (2 tries). Keep tryin

    How can I trap the question 'Could not reserve record (2 tries). Keep trying ?'
    How can I trap the question 'Could not reserve record (2 tries). Keep trying ?'
    I want to know the error_code for this question before the 40501 error code.
    Thanks for the help.

    See
    Could not reserve record (2). Keep trying ?....

  • Pulling up duplicate records

    My custom Forms 6i application pulls up production records. However, if 2 users access the same record, the system locks one of them out. How can I display a message to the locked out user that this record has been locked by another user with that person's name?
    Also, that he has query-only access on the record till the record is released by the other user?

    on form's data block, you need to handle the lock by yourself.
    1) on-lock trigger,
    declare
    row_is_locked Exception;
    pragma exception_init(row_is_locked, -54);
    begin
    select ...into...for update ... nowait;
    /**check your lock_audit table that created first, if the current user is in, if not, insert into that table; if already in, update that table with current time and info.
    lock_record;
    IF NOT FORM_SUCCESS THEN
    RAISE FORM_TRIGGER_FAILURE;
    END IF;
    EXCEPTION
    WHEN row_is_locked THEN
    --query userinfo and alert the new user;
    2) on-update,
    put your update statement;
    3) on-error trigger,
    if error_code =40501 then
    query that audit table to alert the new user-
    It works well on my form, users cannot overwrite any thing. and was happy to see the detailed user info(including phone number and email address) who locked the record.

  • Some question on IDOC (Control Record/Data Record/Status Record)

    Dear all,
    I am new in this area, and would like to enquire some question on this topic.
    When I view a IDOC via WE02, each of the IDOC record will consist of Control Record/Data Record/Status Record).
    Questions:
    I notice that the data records consists of many segment (i.e. E1EDK01, etc) which are use to store application data.
    1 - My question is do I have to manually create all these segment and do a mapping to my application field one by one (i.e. that is when I want to create a brand new message type from scratch)?
    2 - If question no. 1 is Yes, how to do it, what are the transaction code to create it? can you show me the step by step.
    3 - I don't have to create the Control record and the status record for my new message type right ? because those field value will automatically pull out from partner profile and system status message, am I correct?
    Thanks.
    Tuff

    Hi Tuff,
    As everything in SAP, with IDOCs too there are
    1) Standard IDOCs
    2) Standard IDOCs(Extending - Enhancement to an IDOC, to accomodate for custom values)
    3) Custom IDOCs
    And every IDOC has,
    Control record - EDIDC Structure - This mostly reflects the partner profile information, along with few more details which are used for IDOC extension, Sequencing etc
    Data Records - EDID4 Structure - These records contain the actual business data of the document in concern. So for ORDERS05 it would contain order details, INVOIC02 - Invoice details so on...
    Status Records - These records capture the status of an IDOC from the time it is received/sent from your system and a corresponding business document is created/changed. So this will have messages like "IDOC sent to the port OK" etc which are status from the communication layer(ALE) to application specific messages like "Sales Order XXX created" or "Invalid Material" etc.
    You would have noticed something called as Process code in the partner profile, this is associated with a FM(or work flow task etc) which has the business logic coded in.
    So in case of an Inbound IDOC, the sending system updates the IDOC - Control and Data records, and sends it to the receiving system. On the receiving system the IDOC's control record is validated against the partner profiles set, if an entry is found then using the process code it finds the associated FM which will decode the data from the IDOC data records as per the IDOC type and then use it to post data into SAP (VIA BDC, Batch Input, BAPI etc).
    And all this while the Status records are being updated accordingly.
    So with the above context will try to answer your questions,
    1 - My question is do I have to manually create all these segment and do a mapping to my application field one by one (i.e. that is when I want to create a brand new message type from scratch)?
    In case of a custom IDOC, yes you will have  to.
    In case of a standard IDOC, you wouldn't have you just have set up the necessary configuration (Partner Profile, Process code etc)
    In case of a standard IDOC extended to accommodate for some custom values(for which there are no fields in standard IDOC - Let us say you have added some new fields on VA01) - In this case you can still use the standard Process code and Standard FM associated with it, SAP provides several Function exits in these FM's which you can leverage to add your custom logic.
    2 - If question no. 1 is Yes, how to do it, what are the transaction code to create it? can you show me the step by step.
    There are several documents available on the net and on SDN detailing step by step approach for all the above three cases,
    just search for step by step guide for IDOCS - sap.
    3 - I don't have to create the Control record and the status record for my new message type right ? because those field value will automatically pull out from partner profile and system status message, am I correct?
    Again it depends, in case of using a standard IDOC you wouldn't have to. But in case you have some customizations/enhancements then you might have to.
    For Ex: updating the control record accordingly for indicating that you have extended the standard IDOC. Or append custom messages to the status record as per the business logic.
    Try out the examples you find on the net and post any specific questions you might have.
    Regards,
    Chen

  • Question on the status record of Idocs.

    Hi all,
    Where does the status of the idoc update::
    1) In the idoc in the sap system/Idoc Archive
    OR
    2)The one we transfer to the OS as a flat file (for the translators(EDI subsystem) to work on)?
    OR
    both of the above?
    Thanks,
    Charles.

    Hi,
    Whenever the IDOC is generated there are one to many status record updated to idoc depending on it is inbound / outbound and various process / system is goes through.
    Check transaction <b>WE47</b> to see all IDOC related status.
    This is the range of status for IDOC.
    OUTBOUND Idoc - Status between 1 to 49
    INBOUND Idoc  - Status between 50 to 74
    Also you can check the View <b>V_STACUST</b>. If you want to check status(s) of any idoc check table EDIDS.
    Regarding two scenario you are talking about.
    1. In the idoc in the sap system/Idoc Archive.
    - When IDOC is generated, it get status record
    - When you archive already created IDOC, the neither the status records are updated / changed or new status record are created
    2. The one we transfer to the OS as a flat file (for the translators(EDI subsystem) to work on)?
    - If you mean that you are sending IDOC to fine port then yes in that case also IDOC has status records.
    Can you explain your second question in more detail?
    Let me know if you have any other question.
    Regards,
    RS

  • Questions about VOIP and recording in Connect

    Hi,
    We have been using Connect for a long time, but have been doing the audio using AT&T teleconferencing. We were thinking about using VOIP for the webinars we do. I just have a few questions.
    1. Is there a limit of the number of connections to VOIP like there is with the teleconferencing? Is there a point where the number on there could decrease the quality of the VOIP?
    2. When we record the webinar, where can we save it to? Can we save it to our server?
    Any help with these questions would be great. Anything else that would be good to know for doing VOIP and recording?
    Thanks.
    Lisa

    We don't natively integrate with AT&T by the way - so you have to use Universal Voice in this case and set it up yourself. Not hard to do.
    1. No limit on VOIP but we recommend using the optional SPEEX audio codec built into the Host Add-In if using VOIP a lot. It requires everyone to be using the Host Add-In though. Over 150 though and it might get unruly!
    2. Recordings are saved to the Adobe Connect Central portal that every customer has for their rooms. You can create a local copy from there and then copy the local copy to another server. It's a Flash file so you may need to convert it if you don't have a player.

  • Question about interface for recording electric guitar and vocals

    Ok, I've been messing around with Garageband all day, totally stoked and I'm ready to get into it. Right now I'm using a First Act quarter inch plug to USB cord to hook up my guitar and start recording and after some messing around I got it to work.
    Here's my question... to really make quality recordings, what's the best way to hook up the guitar? Is the way I'm doing it now fine with the USB cord or is some sort of interface better? Can someone recommend one that's on the cheap side? Also, I haven't tried yet, but what's the best way to record vocals? Should I invest in a USB mic? Can anyone recommend one? I have a Shure SM58 already, what's the best way to hook that up?
    Really excited about this, can't wait to start cranking out some songs!
    PS: When I use the USB cord, I don't see any way to control the recording level, and sometimes I get a Feedback control warning. How can I lower the level so I don't get that? Thanks!
    Message was edited by: xSlamx

    I have a total now of 4 interfaces - I recently purchased a FOCUSRITE SAPPHIRE 6 USB - it's amazing quality and I only paid $149 for it at my local Guitar Center. I use it with my Guitar and everything sounds fantastic - they say the preamps are really high-quality for Mics too... I recommend it. I have a firewire interface too but the Sapphire is my man baby now - don't let the USB 1.1 fool you - it works flawlessly with my Mac and my Windows 7 machine too. It also comes with a selection of software including Ableton Live Lite and 4 really nice Focusrite plug-ins too.

  • Functional Module Extractor not pulling all the record on BW side

    Hi,
    i have written a FM extractor to pull data from CDHDR and CDPOS table. the Records count shows on RSA3 is more than 3,00,000 but while pulling it on BW side it brings only 41,000  Around records.
    I steps i have taken is -
    tried setting and resetting the package side in Info package.
    Tried putting the default package size to 50K in FM setting
    but nothing is working.
    It seems like the pacet size is not incrementing in the code. i have tired to find ou the fault but coult not and RSA3 is working fine.
    can anyone please suggest a correct piece of code or find out where exactly the fault is?

    Vikrant,
    The structure of your generic extractor function module should be something like:
    If initialisation
      Store parameters, clear packet count
    Else
      If first packet
        Create cursor
      Endif
      Read block of records from cursor
      If cursor returns no more records
        Raise NO_MORE_DATA exception
      Endif
      Process records from cursor and output
      Add one to packet count
    Endif
    This function module code can get called repeatedly.  Possibly you are only extracting data for the first packet?
    Mark

  • Record Selection in Japanese not pulling the correct records.

    Hello,
    I am using Crystal XI running off of a Remedy SQL Database that has Japanese data in the records.  When I place the following criteria in the Record Selection, I pull no records.  But, If the put the criteria with the japanese criteria in the Group Selection formula, I get the records that I want but then many of my formulas are adding up all the records.
    {HPD_HelpDesk_VW.Severity} in ["1","2"] and
    {HPD_Affected_Organizations.Organization} like "ジブラルタ"
    How can I get Crystal to recognize the japanese criteria in the Record Selection criteria?
    Any help would be appreciated.
    Thanks, Stacy

    Hello,
    I am using Crystal XI running off of a Remedy SQL Database that has Japanese data in the records. When I place the following criteria in the Record Selection, I pull no records. But, If the put the criteria with the japanese criteria in the Group Selection formula, I get the records that I want but then many of my formulas are adding up all the records.
    {HPD_HelpDesk_VW.Severity} in \"1\",\"2\" and
    {HPD_Affected_Organizations.Organization} like "ジブラルタ"
    How can I get Crystal to recognize the japanese criteria in the Record Selection criteria?
    Any help would be appreciated.
    Thanks, Stacy

  • Pulling the latest records from the datasource to BW

    Hi,
    I need to pull the most recent records from a custom table on R/3 side. I make use of infoset query to retrieve data from two different tables. One custom table and the other SAP table MAKT. I created a transaction data... Datasource make use of infoset to extract the data on R/3 side.
    Is there a place where I can write code to play around with the data... is there any user exit to write the code for this purpose.
    Need help...

    Trx CMOD:
    1. Enter the Project name; if you dont have an existing project and u have to create one.
    Select a good name for a project..say ZBIW..and then enter the name and click on create button.It will take u to new screen.There give short text for project name.
    Above u will see 'enhancement assignments' button.Click it and in the new screen add enhancement RSAP0001.
    Save and remember to activate project too..
    (save in appropriate transport request)
    2. go to components select the required function module.
    EXIT_SAPLRSAP_001 for Transactional DS
    EXIT_SAPLRSAP_002 for Master DS
    Hope it helps.
    Regards

  • Recording Increment and Percentage Increase for salary changes

    Hi,
    I am undertaking a large HR/Payroll implementation and one of the requirements is to record in SAP the following fields for any salary changes:
    - Absolute Increment - monetary value of an increase
    - Percentage Increase
    I was hoping it would just be sufficient for us to create a bespoke report for this information, however the customer is insistent that they want to record this for each individual.
    Any ideas where this could be stored? I was thinking perhaps of setting up two non-paying WTs in IT15 to record these.
    Thanks
    Hannah

    Hi,
    I am undertaking a large HR/Payroll implementation and one of the requirements is to record in SAP the following fields for any salary changes:
    - Absolute Increment - monetary value of an increase
    - Percentage Increase
    I was hoping it would just be sufficient for us to create a bespoke report for this information, however the customer is insistent that they want to record this for each individual.
    Any ideas where this could be stored? I was thinking perhaps of setting up two non-paying WTs in IT15 to record these.
    Thanks
    Hannah

  • Question on Cisco Compliance Recording

    Hi, anybody worked on Cisco QM or CR(Compliance Recording)? I have a confusion on it. There are three types of recording systems - 'Desktop Recording', 'Server Recording' and 'Network Recording', the installation and configuration guide I have found as well but the confusion is not clear yet.
    I can see the server sizing calculation are for 'Server Recording' or 'Network Recording' mode only, but I have a basic question, for 'Desktop Recording' system don't we need a seperate server? Or the recording files will be stored inside the desktop PC only?
    Thanks,
    Mijanur Rahman
    CCIE# 27424 (Voice)
    dreamforccie.wordpress.com

    You don't need a separete server for desktop recording, it will work just fine with your windows server running the CR.
    So I need a seperate box running windows server with CR installed, isn't it? Because the customer is running CCX 8.5, so no windows environment already there.
    Thanks,
    Mijanur Rahman
    CCIE# 27424 (Voice)
    dreamforccie.wordpress.com

  • Beginner imageIO question (pulling up image over network vs local)

    Greets,
    I am new to java but not too new to programming. I've googled the heck out of this question and checked the java 2D api and haven't had much luck yet. Take a look and let me know what you think:
    I would like to pull up an image file and display it in a jLabel, it works fine if i am pulling up a local file as such:
    BufferedImage img = null;
            try {
                img = ImageIO.read(new File("/home/steve/pic.gif"));
            } catch (IOException e) {
                e.printStackTrace();
            }But what i really want it to do, is pull up a file over the local network, like so:
    BufferedImage img = null;
            try {
                img = ImageIO.read(new File("smb://192.168.1.64/images/pic.gif"));
            } catch (IOException e) {
                e.printStackTrace();
            }However, when i try this second one, i get the following error:
    javax.imageio.IIOException: Can't read input file!
            at javax.imageio.ImageIO.read(ImageIO.java:1275)
            at mypkg.MainForm.load(MainForm.java:143)
            at mypkg.MainForm.<init>(MainForm.java:27)
            at mypkg.MainForm$1.run(MainForm.java:111)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Can anyone point me in the right direction or give me a code snippet? Much appreciated.

    Paul,
    All definately valid points. I was able to get it to work if i mounted the smb share to my local filesystem but essentially i am trying to make the application portable so i dont have to mount a drive on the target machine (or create a windows drive map, etc). Although read(URL input) isnt exactly what i was looking for, it works good enough and gets the same end result. i just have to copy the image folder and serv it up via apache instead of samba.
    Thanx for your input.

Maybe you are looking for