Random selection in SQL query

I have a query or SQL, I write when I need to select the records in this way.
More than these 2 folders and 2 files for each user name should be random.
There are a lot of areas I get through my SQL; but the username there are usually around 20 unique user names.
The data itself without random statement be added return about 2000 discs.

If someone could help me with the syntax of the SQL portion that could achieve the results I'm looking for, I would appreciate it.
I've never tapped into before random selection method.
Someone told me I could use a rank() statement; but I have no idea how to use it.
Then, someone else mentioned to use dbms_random.value which is another that I don't know how to use.

Please let me know if you have any ideas that could help me.

Thank you

my request has just need a slight modification:

SQL> select   deptno, ename
  from   (select   deptno, ename, row_number () over (partition by deptno order by dbms_random.value) rn
            from   emp)
 where   rn <= 2

    DEPTNO ENAME
---------- ----------
        10 CLARK
        10 KING
        20 JONES
        20 ADAMS
        30 MARTIN
        30 JAMES     

6 rows selected.

in my case deptno plays the role of your users!

Tags: Database

Similar Questions

  • Eliminate the duplicate based on the condtion in Select of SQL query.

    Hi all

    I write the SQL query where I have to select values based on the condition in the column.

    Lets say I have 3 columns position, description, used, there are different values in the position but for some positions of the column description of the lines is the same and if column Description is the same and employee is null then that there should be only one row returned and if the description is the same but the employee column is not null then it should be several lines.

    I can't use Group by that we have around 35 columns in the select query.

    Please suggest any Solution.

    Hi Michael,

    I adds a column to the t2 to get the good understanding of my needs.

    Level
    Employee From Date to_date
    1 Test2 21.03.2014 21.04.2014
    2 Test4 21.02.2014 20.03.2014
    2 Test1 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    3 MgrTest 21.03.2014

    Now, the result should look like this.

    Level
    Employee From Date TO Date
    1 Test2 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    2 Test1 21.03.2014 21.04.2014
    3 Mgrtes 21.03.2014
    4

    There was an addition more as if this day is not null for the given level, then the query must return a single line of balnk more with the same position, I am reached using any Union and works very well I'm stuck with the point above.

  • Passing the value of the SQL query select list

    Hello

    In my application users have in their homepage to a region which has two simple things, a part of LIST SLECT lov function and a BUTTON

    There is also another page which has a normal life to report which shows the employees.


    Homepage the user can select certain number of Department in its 'SLECT-LIST' and click 'open '.


    For example: If the user has selected a DEP_NUM_5 and click on the BUTTON it will be redirected to the page of a report and gets only showed the employees belonging to the Department 5.


    The report page contains a simple SQL query, and I understand that somehow I must pass the value in the SELECT LIST, where I now have the '?


    How can I do this, where should I start?

    Of course I would really appreciate an example of code, if anyone has time to do a.

    
    select "EMP_ID", 
    "EMP_FORNAME",
    "EMP_SURNAME",
    "DEP_NUMBER"
    from EMP E
    where E.DEP_NUMBER = ????????
    
    

    Hi Sozua,

    1. create an item hidden on the page where you have the report.

    I say P2_DEPT_NO

    2 assign to that in your sql query

    select "EMP_ID",
        "EMP_FORNAME",
        "EMP_SURNAME",
        "DEP_NUMBER"
        from EMP E
        where E.DEP_NUMBER = :P2_DEPT_NO
    

    below the area source ther is also an option

    Elements of page to submit-> put this element in this.

    for example;

    Page to submit items: P2_DEPT_NO

    3. change your button

    Action: Redirecting to page of this application

    Page: 2 / / assuming that page 2 is the report page

    Place these items: P2_DEPT_NO

    with these values: & P1_SELECT_LIST.  assuming that selection list is on page 1

    Hope this helps you,

    Kind regards

    Jitendra

  • How to select only the part by using the sql query

    Hello

    I have the task to retrieve only the integral of the input text by using the sql query.

    The entry is as follows

    Entry for the price setting

    $12.5 (FYI without space)

    $ 12.5 (FYI single space)

    $ 12.5 (double space FYI)

    $12.5 (FYI multiple space)

    $12.5 (FYI multiple space)

    Output expected of 12.5

    The price is the type varchar2 column in the store_price table.

    Please let me know how to achieve this.

    Thanks in advance.

    If this is always the case that you get a $ followed by a number of places, you can use something like:

    Select to_number (ltrim ('$ 12.5',' $')) DOUBLE

    or

    SELECT ltrim ('$ 12.5',' $') OF double

    but take care of your nls_numeric_character settings if they are defined so that, for example, a comma is the decimal separator, you will have a problem.

    HTH

  • Select SQL query

    Hello

    I have a table named demo with two columns (name brands), as shown below

    Name brands
    A 80
    B 100
    C 96
    I need a Select SQL query that returns the result as shown below

    Name brands
    A 276
    B 276
    C 276

    Brands of column must contain the sum of all the brands of the table against each of the name of the table. (Not necessarily with the same columns as the demo table names) This result should not be stored in the table and I need it just for display purpose.

    Published by: 944160 on May 30, 2013 05:28

    Try this

    select
    name,
    sum(marks) over () marks
    from
    demo
    
  • How to use the multiple selection list values in sql query

    Hi all
    In the search form, I have a multiselect llist tell (P3_STATUS) and I want to have a query using this element and fetch documents
    How to do a sql query based on the selection of the value of this element.
    SELECT "W"."START_DT" "Start Date",
           "W"."CAMPAIGN_CODE" "Campaign Name",  
           "W"."MKT_CHANNEL" "Channel",
           "W"."MKT_SUB_CHANNEL" "Sub Channel", 
           "W"."PROMO_CODE" "Promo Code",
           "W"."TRACKING_CODE" "Tracking Code",
           "W"."TFN" "TFN",
           "W"."STATUS" "Status",
           "W"."CAMPAIGN_CODE" "Edit"
           FROM 
             "WC_MKT_CAMPAIGN_DS" "W"
      
           WHERE 
         (MKT_CHANNEL = decode(:P1_CHANNEL,'%null%',MKT_CHANNEL,NULL,MKT_CHANNEL,:P1_CHANNEL))
       AND
    (MKT_SUB_CHANNEL= decode(:P1_SUB_CHANNEL,'%null%',MKT_SUB_CHANNEL,NULL,MKT_SUB_CHANNEL,:P1_SUB_CHANNEL))
    AND *STATUS = decode(.................*
    Please could someone help me on this?

    Thanks in advance
    Robert L

    Try to change your selection of status to

    AND INSTR(':'||:P3_STATUS||':',':'||STATUS||':') > 0
    
  • Data model - SQL query

    Hello world

    I hope someone can point me in the right direction.

    I have the SQL code following in the type of SQL query data model.

    Select * from ap_invoices

    The following select statement is not to return all the rows in the view, but the fact of sqlplus.

    I have setup the EBS security model uses BEEP 10.1.3.4.1.


    What I do wrong, is there some setting I'm missing?

    Do I need to use a different security model to BEEP?

    Help, please
    Thank you.

    Hello

    AP_INVOICES is a view as you know, sound based on the ORG_ID set when you select from it. IM thinking that when you use just select * from AP_INVOICES at RANDOM. Its not abreast of your org id and its is not defining for you when you run a query, so its not rehired data. Two options:

    1. use a data model and in the pre-reading trigger set the context of the org. As you may be in an Oracle report. Data models are very powerful and offer everything that OReports done in EBS incl. triggers flex extensions

    2 use the AP_INVOICES_ALL table and set the org id in the query where clause.

    Both approaches need so that you know the id org that you want to set. The integration of the security that you won't it's to say it does not pass it when the user opens a session. I suppose you have a report folder for every responsibility you could hardcode the org id in the reports in a given folder. Or you can add it as a parameter to the user to fill out report.
    Integration level just does not quite go enough away for the time to manage the org and, therefore, the views of the org.

    hope this is clear

    Concerning

    Tim

  • Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit

    I have this SQL query:

    DECLARE TABLE (@DataTypeTable)
    Name varchar (128).
    TypeID INT)

    -Add comma delimeted type data in the temporary table names
    INSERT INTO @DataTypeTable (name)
    SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')

    SELECT the name OF @DataTypeTable

    That takes a comma delimited by the string and returns the string as a table.  It works correctly in Microsoft SQL Server Management Studio.  When I run this as a stored procedure I return nothing.  There are no errors, SQL or otherwise.  I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above).  Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?

    Thanks in advance.


  • SQL query for empty string

    I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.

    I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.

    Thanks in advance for your help,

    Jim

    Jim,

    Just to be sure, have you used 'is' instead of '=' in this command?

    This makes all the difference in this command.

    Cerati

  • Support of SQL query: what tasks are Sunday from 07:00 - 12:00

    Hello tide Admins.

    I need to do a SQL query that can give me a list of jobs that are running on a given (Sunday) day from 07:00 - 12:00.  Our environment is not a maintenance window.  Therefore, whenever there is application of patches or upgrades, it causes more work and risk of failure of the tide tasks.    By moving jobs over the period from 07:00 - 12:00 Sunday, patch can be completed without disrupting the calendar.

    Im not the best at the SQL script and can not get my script to work. any help would be great. Here's what I have so far.  I get the error ' could not find identifier multi-player jobmst.jobmst_name.  IM using Tidal 6.0.3 with SQL for DB Admeral table.

    SELECT dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name

    FROM dbo.jobdtl INNER JOIN

    dbo.jobmst ON dbo.jobdtl.jobdtl_id = dbo.jobmst.jobdtl_id

    WHERE (dbo.jobdtl.jobdtl_fromdt > 14 September 2016 06:00 ') AND (dbo.jobdtl.jobdtl_fromdt< '09/11/2016="" 012:00:00="">

    GROUP OF dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name

    Hi Jeff

    The time window from the jobdtl returns only jobs that have an early start time and windows of time from beginning to the end, so there may be some tasks which are not time bound but have dependencies on other jobs, variables, etc.

    Here are the 2 SQL queries against the table jobrun and jobmst:

    -The list of jobs that took place last Sunday between 07:00 and 12:00

    SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_time FROM jobrun
    JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
    WHERE jobrun.jobrun_time > = 9/11/2016 07:00 ' and jobrun.jobrun_time<= '9/11/2016="" 12:00="">
    ORDER BY jobrun.jobrun_time

    -For a list of jobs that are scheduled to run on Sunday to come between 07:00 and 12:00

    SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_esttime FROM jobrun
    JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
    WHERE jobrun.jobrun_esttime > = 9/18/2016 07:00 ' and jobrun.jobrun_esttime<= '9/18/2016="" 12:00="">
    ORDER BY jobrun.jobrun_esttime

    ARO

    The Derrick

  • How to get the value of a column in sql query?

    Hi, anyone knows how to get the value of a column in sql query?

    Here is my code, the value must be 1350079224397 in my PB, but I get 0

    QString query ("SELECT version FROM db_version");

    QVariant result = sda.execute (query);
    QVariantMap versionMap = result.toList () such () .toMap ();
    If (! versionMap.IsEmpty ())
    {
    qDebug()<"Version: "=""><>
    }

    OK, I have the solution

    QString query ("SELECT version as version FROM db_version");

  • Looking for a SQL query to retrieve callvariables + ECC to a RESULTS of SCRIPT EXECUTE (translation VRUS)

    Hi team,

    I'm looking for a SQL query check data (ECC + CallVariable) due to a RESULT of SCRIPT EXECUTE when you ask an external VRU with a translation route to VRU with a 'run external Script '.

    In my view, that the data are analyzed between the termination call detail + termination call Variable.

    If you have already such a SQL query I would be very grateful to have.

    Thanks and greetings

    Nick

    Omar,

    respectfully, shorten the interval of a day might not be an option for a history report ;-)

    I recommend to take a look at the following SQL query:

    DECLARE @dateFrom DATETIME, @dateTo DATETIME

    SET @dateFrom = ' 2014-01-24 00:00:00 '

    SET @dateTo = ' 2014-01-25 00:00:00 '

    SELECT

    TCV. DateTime,

    TCD. RecoveryKey,

    TCD. RouterCallKeyDay,

    TCD. RouterCallKey,

    VME. EnterpriseName AS [ECVEnterpriseName],

    TCV. ArrayIndex,

    TCV. ECCValue

    OF Termination_Call_Variable tcv

    JOIN THE

    (SELECT RouterCallKeyDay, RouterCallKey, RecoveryKey IN Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime)< @dateto)="">

    THE tcv. TCDRecoveryKey = tcd. RecoveryKey

    LEFT OUTER JOIN Expanded_Call_Variable VME ON tcv. ExpandedCallVariableID = VME. ExpandedCallVariableID

    WHERE the tcv. DateTime > @dateFrom AND tcv. DateTime<>

    With variables, you can set up your code (for example, you could write SET @dateFrom =? and let the calling application to fill in the DateTime for you).

    In addition, join two large tables with all the lines, as you did (TCD - TCV) is never a good option.

    Another aspect to consider: all the ECC is actually arrays (always), is not good to leave aside the index value (tcv. ArrayIndex).

    G.

  • DA on updatable report items Sql query using the class

    Request Express 4.2.5.00.08

    10-11 g Oracle

    I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.


    However, I've now added some complex things.

    for example. My region is based on the query of SQL Type (editable report).

    SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;

    I can also add a new line of course.

    My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.

    for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.

    And now, I created the DA.

    1. event: change

    Selection type: jQuery Selector

    jQuery Selector: .st_tm

    Condition: No.

    1. action: set value

    Set type: Expression Javascript

    The JavaScript Expression: $(this.triggeringElement) .val ();

    The element affected: P10_X1 (it is a hidden item)

    2. action: Plsql Code

    Code: start to null; end;

    Page items to submit: P10_X1

    3. action: Plsql Code

    Code: start

    If: P10_X1 between '03' AND '11' then

    : P10_X1: = 'EARLIES ';

    elsif: P10_X1 then '12' and '18'

    : P10_X1: = 'LATES ';

    on the other

    : P10_X1: = 'NIGHTS';

    end if;

    end;

    Page items to submit: P10_X1

    NOW another DA

    Event: change

    Article (s) P10_X1

    Condition (in list)

    value (HASTY, LATES, NIGHTS)

    Action:

    Set type: Expression Javascript

    The JavaScript Expression: $(this.triggeringElement) .val ();

    Affected item:

    Selection type: jQuery Selector

    jQuery Selector:. Shift_time

    Well, I look forward all the above work well, but I'm having a problem.

    If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.

    I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?

    Help, please!

    Kind regards

    RI

    I found the solution me thank you.

    I removed all the DA mentioned above and created a new.

    1. event: change

    Selection type: jQuery Selector

    jQuery Selector: .st_tm

    Condition: No.

    Scope of the event: dynamic and light on page load.

    Action (Javascript code)

    ROW_ID = $(this.triggeringElement).attr('id').substr (4);

    If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">

    .Val ('EARLIES') $(«#f11_» + row_id);

    }

    ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">

    .Val ('LATES') $(«#f11_» + row_id);

    }

    ElseIf (. val() > $19 (this.triggeringElement)) {}

    .Val ('NIGHTS') $(«#f11_» + row_id);

    }

    also created another DA because I have a disabled report items.

    Event: before the page is sent.

    $('_:_disabled').removeAttr ("disabled");

    and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).

    Kind regards.

  • SQL query to retrieve only numbers to a string variable

    Dear all Experts,

    I have a requirement in one of my projects where I need to extract only the numbers present in the variable.

    for example:

    BANK_ACCOUNT_NUMBER = 12345-67890';

    BANK_ACCOUNT_NUMBER = 12345 67890';

    BANK_ACCOUNT_NUMBER = "123.456.7890";

    BANK_ACCOUNT_NUMBER = 123-A456BC7890D';


    In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.


    Please suggest me the query how to extract numeric values from varchar variable.



    Thank you

    Knockaert

      select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
    

    See you soon,.

    Manik.

  • Calculation of the time wall of a SQL query.

    Hello

    While trying to discover the time of running a SQL query (wall time) I read in one place that CPU_TIME/EXECUTIONS of v$ SQLAREA, is the precise runtime we can come close to.

    I can't use "set timing on ' or 'DBMS_UTILITY. GET_TIME' that I need to extract the execution time of the story because the query will be drawn to an end, and I need to know how long it took to DB level and compare it with the end time before calculating the % of time used in the DB level total.

    Maybe another way to track sessions and the user TKPORPOF but now I donot want to take the help of the ADMINISTRATOR at this initial stage.

    Is CPU_TIME/EXECUTIONS of v$ SQLAREA where (SQL_TEXT) AS "SELECT... OF... %'; should be enough?

    user2925917, yes as Brian already answered your understanding as posted above seems correct.  Except in the case where there has been only a running query you will download an average time.  The problem with averages is that one or two unusual executions that can skew the average, but in most cases the average will be probably fairly accurate.

    - -

    HTH - Mark D Powell.

Maybe you are looking for

  • iMovie canvas size

    Someone knows how to change the canvas size in iMovie to 750 x x 1334 h?

  • Problem with new PC Toshiba laptop

    I don't have good experience with Toshiba as a great brand. I brought a new laptop of dicksmith elizabeth her (SR4192426). At the time of the sale, the saleman said if you have a problem with the machine to come back and we can repair or replace. Thi

  • Re: Satellite A300D - 14 p - XP stops in the middle of the installation

    Hello! Why when I install Windows XP on my PC overheated and stops in the middle of the installation? Why windows XP run so long, on the other PC as windows loads by 3 times faster! My PC is Satellite A300D - 14 p PSAKE8E

  • enum in ascii

    How can I convert an enum.. ASCII data type ?

  • How to install RAM

    Hello I have a HP Pavilion elegant book 14 b 010 - we and it came with 4 GB of ram expandable to 8 GB. I have a new ram of 4 GB ready to install, but the back of the computer does not come off. For theis particular model, you know how to install RAM?