Number of conditional group

Hello world

I want to give a group according to the number of my condition. How can I do tah.

For example; My data are below.

Select k.*

from (select e.*

lead (e.salary) over (partition by order by e.hire_date ASC e.department_id) diff

e employees

where department_id = 30) k

1114DenRaphaelyDRAPHEAL515.127.456107.12.1994PU_MAN11000,00100303100
2115AlexanderKhooAKHOO515.127.456218.05.1995PU_CLERK3100,00114302800
3117SIGALTobiasSTOBIAS515.127.456424.07.1997PU_CLERK2800.00114302900
4116ShelliBaidaSBAIDA515.127.456324.12.1997PU_CLERK2900,00114302600
5118GuyHimuroGHIMURO515.127.456515.11.1998PU_CLERK2600,00114302500
6119KarenColmenaresKCOLMENA515.127.456610.08.1999PU_CLERK2500.0011430

And I want to just translate as follows

Rule: If diff column < 3000 then give same identical number from the previous row, if diff > 3000 or null column gives a new group number.

1114DenRaphaelyDRAPHEAL515.127.456107.12.1994PU_MAN11000,001003031001
2115AlexanderKhooAKHOO515.127.456218.05.1995PU_CLERK3100,001143028002
3117SIGALTobiasSTOBIAS515.127.456424.07.1997PU_CLERK2800.001143029002
4116ShelliBaidaSBAIDA515.127.456324.12.1997PU_CLERK2900,001143026002
5118GuyHimuroGHIMURO515.127.456515.11.1998PU_CLERK2600,001143025002
6119KarenColmenaresKCOLMENA515.127.456610.08.1999PU_CLERK2500.00114303

Thank you very much.

Emrah mete wrote:

I'm so sorry. I made a mistake when I tried to copy - paste result of desire.

My desire to result is followed.

1 114 Den Raphaely DRAPHEAL 515.127.4561 07.12.1994 PU_MAN 11000,00 100 30 3100 1
2 115 Alexander Khoo AKHOO 515.127.4562 18.05.1995 PU_CLERK 3100,00 114 30 2800 2
3 117 SIGAL Tobias STOBIAS 515.127.4564 24.07.1997 PU_CLERK 2800.00 114 30 2900 2
4 116 Shelli Baida SBAIDA 515.127.4563 24.12.1997 PU_CLERK 2900,00 114 30 2600 2
5 118 Guy Himuro GHIMURO 515.127.4565 15.11.1998 PU_CLERK 2600,00 114 30 2500 2
6 119 Karen Colmenares KCOLMENA 515.127.4566 10.08.1999 PU_CLERK 2500.00 114 30 2

Well now your output still does not match the rule, because the value null is not changing the sequence as he said.  However, if you want it is a quick change to my previous question...

SQL > ed
A written file afiedt.buf

1. Select k.employee_id, k.first_name, k.last_name, k.diff
2, sum (diff_change) (any order by employee_id) as seq
3 from (select k.*
4, case when diff is null then 0 / * do not change if the value is null * /.


5 when nvl (lag (diff) over (order by employee_id), 0) < 3000="" and="" diff=""> = 3000 then 1
6 when nvl (lag (diff) over (order by employee_id), 3000) > = 3000 and diff< 3000="" then="">
7 0 otherwise end as diff_change
8 of)
9. Select e.*
10, lead (e.salary) over (partition by order by e.hire_date ASC e.department_id) diff
11 e employees
where the 12 department_id = 30
13                ) k
14 *) k
SQL > /.

EMPLOYEE_ID, FIRST_NAME LAST_NAME DIFF SEQ
----------- -------------------- ------------------------- ---------- ----------
114 1 3100 den Raphaely
Alexander 115 2800 2 Khoo
Shelli 116 2 2600 Baida
SIGAL 117 2900 2 Tobias
Guy 118 2500 2 Himuro
119 Karen Colmenares 2

6 selected lines.

Tags: Database

Similar Questions

  • Conditional group

    Hello
    I need to make a conditional group based on the values of column grouped without the help of the trade unions. Is it possible to do in a single query...
    I need e exit suite
    with the trial as
    (
    Select 1 as col1, 10 as double amt
    Union
    Select 2 as col1, 11 as double amt
    Union
    Select 1 as col1, 12 as double amt
    Union
    Select 2 as col1, 13 as double amt
    Union
    Select 1 as col1, 14 as double amt
    )
    Select col1, sum (amt) test col2
    where col1 = 1
    Group of col1
    Union of all the
    Select col1, col2 amt test
    where col1 <>1

    Thanks in advance

    Hello

    Try something like:

    SQL> with test as
      2  (
      3  select 1 as col1 , 10 as amt from dual
      4  union
      5  select 2 as col1 , 11 as amt from dual
      6  union
      7  select 1 as col1 , 12 as amt from dual
      8  union
      9  select 2 as col1 , 13 as amt from dual
     10  union
     11  select 1 as col1 , 14 as amt from dual
     12  )
     13  select distinct
     14         col1
     15  ,      case when col1 = 1 then sum(amt) over (partition by col1) else amt  end col2
     16  from   test;
    
          COL1  COL2
    ---------- -----
             1    36
             2    11
             2    13
    
    3 rows selected.
    
  • How to count the number of conditionally highlight cells in a column or row

    I'm working on a table to identify problems with my credit rating. So, I have a column that indicates the due date on the invoice and G that contains the date to which I made the payment.

    I'm trying to follow how many times I'm late with payments. I want to improve.

    So if the G column is later than column D, both with the Date formatting. So, now I've highlighted cells and I want to summarize for the year, how many times I was late payments.

    I thought a column G to count the number of days before or after that back I was with payments. But if the sum, it only gives me no useful information. I guess I could count the number of cells with values less than 0.

    I prefer to be able to put in the summary column for G something that said 0-12 years ago has highlighted cells in the column.

    Thank you

    You can not count based on sharing or formatting.  You can, however, be based on the same conditions.

    There are functions:

    COUNTIF() counties based on a condition is true

    and

    COUNTIFS() based on several conditions being true

    = NB. If

    Here is a way.  IT will take an additional column that calculates the "delay" in the days of a payment

    the first two lines are the lines of header

    H3 = IF (COUNTA (D3, G3) > 1, MAX ((G3−D3) DUR2DAYS, 0), "")

    It's shorthand dethrone select cell H3, and type (or copy and paste it here) the formula:

    = IF (COUNTA (D3, G3) > 1, MAX ((G3−D3) DUR2DAYS, 0), "")

    Now select cell H3, copy

    Select the H3 cells at the end of column H, dough

    H1 = "payments late =" & COUNTIF(H,">0")

  • Consecutive date grouping and find the largest number of consecutive group

    Hi all

    I have given dates and I want to find the largest number of consecutive dates

    WIN_DATE_DATA

    2015-09-22

    2015-09-23

    2015-09-27

    2015-09-28

    2015-09-29

    2015-09-30

    2015-10-1


    In this example, there are 2 group of consecutive dates

    Group 1

    2015-09-22

    2015-09-23

    Group 2

    2015-09-27

    2015-09-28

    2015-09-29

    2015-09-30

    2015-10-1


    The OUTPUT should 5 which is the largest grouping of consecutive number.


    Thanks in advance for the help!




    Please take a look at the Community document: 101 PL/SQL: grouping sequence ranges (method Tabibitosan)

    will allow you to do.

  • power-sum with condition group

    Hello
    I'm fighting with these totals.
    I can't understand the syntax <? sum (current - group (/AMOUNT))? > condition AMOUNT > 100.
    What I want him to have Total of any amounts that are greater than 100 for example. This 100 is supposed to be variable.

    I tried some things that have been proposed in the forum, but all raise error.

    You can try some thing like that

    [100])? >

    can you send me your model you use.

    E-mail: [email protected]

  • number of conditional, exclusion of the counted and other.

    Hi guys,.

    I have the following table:

    MATRIX - ID - Reason_1___Reason_2

    001004 7 B - 2014/04471 2

    001004 R/2014/000046 8 1

    001004 R/2014/000963 7 1

    001001 R/2014/000963 7 1

    001004 102311427365 7 1

    001004 102311428653 8 1

    001004 102311429331 7 1

    001004 102311429818 7 1

    001001 102311429818 7 5

    001004 14 - 0027835 7 1

    001001 14 - 0124520 7 1

    001004 14 - 0124520 2 1

    001004 7 1 2014MEL008627

    001004 7 1 2014MEL013736

    001004 7 1 2014MEL013737

    I need a meter that shows me the following:

    3 separate ID are displayed for both, matrix 001004 and 001001 (those who are R/2014/000963 102311429818 14-0124520)

    9 separate ID appear only for 001004 (3 above must have been excluded).

    0 distinct ID appear only for 001001 (the first 3 should have been excluded).

    No idea how to solve this problem?

    SQL> with t
      2  as
      3  (
      4  select '001004' matrix, 'B-2014/04471' id, 7 reason_1, 2 reason_2 from dual union all
      5  select '001004' matrix, 'R/2014/000046' id, 8 reason_1, 1 reason_2 from dual union all
      6  select '001004' matrix, 'R/2014/000963' id, 7 reason_1, 1 reason_2 from dual union all
      7  select '001001' matrix, 'R/2014/000963' id, 7 reason_1, 1 reason_2 from dual union all
      8  select '001004' matrix, '102311427365' id, 7 reason_1, 1 reason_2 from dual union all
      9  select '001004' matrix, '102311428653' id, 8 reason_1, 1 reason_2 from dual union all
     10  select '001004' matrix, '102311429331' id, 7 reason_1, 1 reason_2 from dual union all
     11  select '001004' matrix, '102311429818' id, 7 reason_1, 1 reason_2 from dual union all
     12  select '001001' matrix, '102311429818' id, 7 reason_1, 5 reason_2 from dual union all
     13  select '001004' matrix, '14-0027835' id, 7 reason_1, 1 reason_2 from dual union all
     14  select '001001' matrix, '14-0124520' id, 7 reason_1, 1 reason_2 from dual union all
     15  select '001004' matrix, '14-0124520' id, 2 reason_1, 1 reason_2 from dual union all
     16  select '001004' matrix, '2014MEL008627' id, 7 reason_1, 1 reason_2 from dual union all
     17  select '001004' matrix, '2014MEL013736' id, 7 reason_1, 1 reason_2 from dual union all
     18  select '001004' matrix, '2014MEL013737' id, 7 reason_1, 1 reason_2 from dual
     19  )
     20  select matrix
     21       , count(case when cnt > 1 then 1 end) common_id_count
     22       , count(case when cnt = 1 then 1 end) unique_id_count
     23    from (
     24            select matrix
     25                 , id
     26                 , count(distinct matrix) over(partition by id) cnt
     27              from t
     28         )
     29   group
     30      by matrix;
    
    MATRIX COMMON_ID_COUNT UNIQUE_ID_COUNT
    ------ --------------- ---------------
    001001               3               0
    001004               3               9
    
    SQL>
    
  • get the maximum number for each group

    Hi, I am a newbie and work on a project for school. I worked this problem for a few days and made a bit of progress.
    I have two tables, student and register for a database of the College. I need to show students that have the most entries into each large. So far, I have:

    WITH COUNT_Q AS
    (
    SELECT B.SSN, B.MAJOR, COUNT (A.CLASS_NO) AS COUNTCLASS
    TO REGISTER A, STUDENT B
    WHERE A.SSN = B.SSN
    B.SSN GROUP, B.MAJOR
    )

    SELECT MAX (COUNTCLASS), MAJOR
    OF COUNT_Q
    GROUP BY MAJOR
    ;

    I get the correct results, but need to introduce the SSN and the Major of the studens. When I add in the SSN and major, as below, I get too many files.
    WITH COUNT_Q AS
    (
    SELECT B.NAME, B.SSN, B.MAJOR, COUNT (A.SSN) AS COUNTCLASS
    TO REGISTER A, STUDENT B
    WHERE A.SSN = B.SSN
    B.NAME, B.SSN, B.MAJOR GROUP
    )

    SELECT *.
    OF COUNT_Q
    WHERE (COUNTCLASS) IN (SELECT MAX (COUNTCLASS)
    OF COUNT_Q
    GROUP BY MAJOR
    )
    ;

    Can someone point me in the right direction?
    SELECT  B.NAME,
            B.SSN,
            B.MAJOR
      FROM  (
             SELECT  B.NAME,
                     B.SSN,
                     B.MAJOR,
                     COUNT(A.CLASS_NO) SSN_MAJOR_COUNTCLASS
                     DENSE_RANK() OVER(PARTITION BY MAJOR ORDER BY COUNT(A.CLASS_NO) DESC) RNK
               FROM  ENROLL A,
                     STUDENT B
               WHERE A.SSN = B.SSN
               GROUP BY B.NAME,
                        B.SSN,
                        B.MAJOR
            )
      WHERE RNK = 1
    /
    

    SY.

    Published by: Solomon Yakobson, March 27, 2011 18:53

  • Conditional formatting - stumped!

    I need to integrate a large number of conditions in my .rtf model in order to get the correct data to print a single column and am received my results when I get one or 2 conditions, but when I add the rest results are all screwed up! I tried to use the instr function, but I must not be doing right b/c if I check it is! = 0 or 0 results are the same.

    <? xdofx:If instr (TITLE, 'Secretary', 1, 1)! = 0 ? > <? TITLE? > <? end if? >
    <? xdofx:If instr (TITLE, 'Secretary', 1, 1) = 0? > <? ORGANIZATION? > <? end if? >-if the TITLE field contains the word 'Secretary' I want to print the TITLE, if the word is not in the title I want to print a different field, but I get the two fields on my report (I tried to use <? another? >, but which no longer works)

    Currently, I have the following code in my article where I want the printed results:

    <? for-each - group:current-group(); / TITLE? >
    <? If: contains(TITLE,'Secretary') or (TITLE, 'Chief') contains or contains (TITLE, 'Director') and (BRANCH! = ")? > <? TITLE? > <? end if? >-it works
    <? If@row:contains (TITLE, 'Secretary')? > <? attribute@InContext:background-color;' #ff99cc '? > <? end if? >-it works

    <? If: not (contains (TITLE, 'Secretary')) or not (contains (TITLE, 'Chief')) or not (contains (TITLE, 'Director')) and (BRANCH! = ")? > <? ORGANIZATION? > <? end if? >- If I add to this, I get the title and the Organization printed
    <? end foreach? >

    I have other conditions that I need to add more, based on the title not containing is not the above values, and if the Division field is / is not null to print other values in the field.

    As you can probably I'm trying to learn to code everything, and I'm not sure what the difference between the use of <? xdofx:If? > or <? If? >. My xml file is the result of a report generated using APEX. I use the desktop version of BI Publisher. Does make a difference as to what the model that I use?

    Any help would be appreciated... I've looked through the guide, but found no examples as involved as what I need, in the style code that I use (<? if...? >).
    Thanks in advance!
    T

    try to replace

    TO

  • County group

    Hello

    Does anyone know if there is a function to calculate the amount of groups? I know there is a to calculate the number of channels: ChnNoMax but I can't find one to calculate the amount of groups

    Basically, what I want to do is to clear all the groups in the data portal to start with a data portal empty. To do this, the only function that I know is: "Data.Root.ChannelGroups.Remove (groupnumber)" and I want to use it in a loop For, but for this I need to know the last value of the loop For that is the number of groups...

    Thank you

    Hi Leillo,

    To count the number of channel groups use

    Data.Root.ChannelGroups.Count

    Please play around with the data API we implemented in DIAdem. It contains all the data that you see in the Dataportal. You can also have a look at the example script of DIAdem. Most of them use it.

    Greetings

    Walter

  • How to find the number of data items in a file written with the ArryToFile function?

    I wrote a table of number in 2 groups of columns in a file using LabWindows/CVI ArrayToFile... Now, if I want to read the file with the FileToArray function so how do I know the number of items in the file. during the time of writing, I know how many elements array to write. But assume that I want the file to be read at a later time, then how to find the number of items in the file, so that I can read the exact number and present it. Thank you all

    Hello

    I start with the second question:

    bytes_read = ReadLine (file_handle, line_buffer, maximum_bytes);

    the second argument is the buffer to store the characters read, so it's an array of characters; It must be large enough to hold maximum_bytes the value NULL, if char [maximum_butes + 1]

    So, obviously the number of lines in your text tiles can be determined in a loop:

    Open the file

    lines = 0;

    While (ReadLine () > 0)

    {

    lines ++;

    }

    Close the file

  • In the Contacts file, cannot create new contact groups

    The menu instructions help to declare the following: in the toolbar, click New Contact Group, type a name in the group name box and then fill in the tabs of the Contact Group and contact information group. You do not have to fill in all the boxes; Just type as much information as you want about the new contact group you create.

    Everything would be easier if "New group contact" appeared on the toolbar.  He isn't here.  I was in the past, because I have a number of contact groups in the file.  What happened to him?

    Please repost your question in the Forum program: http://social.answers.microsoft.com/Forums/en-US/vistaprograms/threads where people who specialize in programs other than Vista and IE (like Windows Contacts) will be more than happy to help you with your question.

    Good luck! Lorien - a - MCSE/MCSA/network + / A +.

  • members of reading address book group

    Hello

    I'm fighting to read the address book of members in a group.

    By doing below:

    BlackBerryContactList = contact list

    (BlackBerryContactList) BlackBerryPIM.getInstance () .openPIMList (PIM. CONTACT_LIST, PIM. READ_ONLY);

    Elements of the enumeration = contactList.items (BlackBerryContactList.SEARCH_GROUPS);

    I was able to get the name of the group. But I don't know how to read his name and phone number of the group.

    Help me please read the address book of the Member.

    I spent several days now.

    Thank you

    DK

    The enumeration returned by contactList.items (BlackBerryContactList.SEARCH_GROUPS) contains BlackBerryContactGroup objects. Using this object you can get each Member as a Contact by calling BlackBerryContactGroup.getContact (int index).

  • The combination of several AD ACS 4.2 security groups

    Hello

    Our ACS is used for AAA for the wireless, the IOS CLI access and access to the unix server. For net admins and administrators unix, there are two levels, so indeed, we have 5 groups of individual devices that a user can be granted access.

    User groups are defined in Active Directory.

    I am looking for a way to combine information from several AD security groups to determine what a user can access. For example, a net administrator may or may not be a unix admin as well.

    Is it possible to do other than to have to have a large number of ad groups with one for each combination of authorization privileges?

    Thank you

    Luke

    HI Luke,.

    Definition of mapping of the hybrid is the best way to achieve this.

    Kind regards

    ~ JG

    Note the useful messages

  • Access control and security group

    Hi all

    I need to know about the access control and what data are suitable for the security group and roles if I have the script like this:

    i. There are 2 different app namely ARA (96 branches with different types of reports) and TRACS400 (6 branches with different types of reports)

    II al ' ARA, users of Branch01 can NOT check Branch02.

    III. different report type is measured by Branch01 and Branch02 are different.

    IV. in Branch01, there are some reports are Read (Cannot download) only and some reports are read and write (downloadable).

    My questions are:

    1. from the above scenario, do I need create all the 96 security group and assign it to different leadership roles?

    2. How can I control read and write access, as I have tested the READ access the user is still able to download the report.

    3. How can I control to branch 01, report Type A is a read and report Type B read and write access?

    4. I noticed that if I use the account, the security group can be used be limited to 50 only security groups. Is this good? I may be an application later in the future. These 2 request for test only. But if I do not use the account, there are any number of security groups that can be used?

    Appreciate for your help.

    Hi aziela

    As mentioned by the friends of the forum, it is advisable to have the minimum security group given that its impact on the scalability of the application (rule). Accounts provide the best security solution of dimension view group.

    Security group corresponds to the role, role is mapped to the users. The permissions are obtained at the level of role-SG.

    Accounts are mapped directly to users. So you can have a precise control at the level of the user (eliminating the abstraction of the role).

    All these aspects are impacting performance where rule of thumb is mentioned in the documentation. In general, if a user belongs to many groups and accounts then it will take more time to process the request of content for this user.

    w.r.t. prohibiting the read-only users so that they will not be able to download content, there is a setting, please try option mentioned in this link http://docs.oracle.com/cd/E14571_01/doc.1111/e10792/e01_interface001.htm#CACCFHHA

    WRT performance calculation, see http://docs.oracle.com/cd/E14571_01/doc.1111/e10792/c03_security003.htm#CSMSP143

    Hope this helps

  • SQL error: ORA-00979: not a GROUP BY

    Hi team,

    I am trying to execute the query

    SELECT DISTINCT comp.company_name |' -' || COMP.contract_number AS 'company_name '.

    , UPPER (bh.first_name) AS 'budget_holder '.

    , INITCAP (sup.first_name) |' -' || SUP. Surname AS 'supervisor '.

    , INITCAP (emp.status) AS "Department".

    , INITCAP (emp.first_name |) » '|| EMP. Surname) AS "employee."

    r.employee_id

    , emp.paaf_number AS 'paaf_num '.

    , emp.employee_payroll_number AS 'payroll_num '.

    , emp.discipline AS 'discipline '.

    , NVL (SUM (tg.week_day1), 0) AS "day 1".

    , NVL (SUM (tg.week_day2), 0) AS "day 2".

    , NVL (SUM (tg.week_day3), 0) AS day '3 '.

    , NVL (SUM (tg.week_day4), 0) AS "day4.

    , NVL (SUM (tg.week_day5), 0) AS "day5".

    , NVL (SUM (tg.week_day6), 0) AS "day6.

    , NVL (SUM (tg.week_day7), 0) AS "day 7".

    r.valid_from

    r.valid_to

    Tw_roster_data r

    JOIN tw_employee emp

    ON emp.employee_id = r.employee_id

    JOIN tg tw_timesheet_stage

    ON tg.employee_id = r.employee_id

    AND tg.week_commencing = r.valid_from

    JOIN the tw_contracting_company comp

    ON comp.contracting_company_id = r.contracting_company_id

    JOIN tw_supervisor sup

    ON sup.supervisor_id = tg.supervisor_id

    JOIN tw_budget_holder bh

    ON bh.budget_holder_id = sup.budget_holder_id

    WHERE r.contracting_company_id = 101

    AND r.VALID_FROM = January 31, 2015.

    AND r.VALID_TO = February 6, 2015"

    Group of r.employee_id, comp.company_name, bh.first_name,

    EMP.paaf_number, emp.employee_payroll_number, emp.discipline,

    r.valid_from, r.valid_to;

    But still the error below

    Error in the command line: 1 column: 17

    Error report-

    SQL error: ORA-00979: not a GROUP BY expression

    00979 00000 - "not a GROUP BY expression"

    Can help.

    Hello

    When to use analytical function oracle other columns used based on the analysis, must be included in the GROUP BY Clause

    SELECT expression1, expression2, ... expression_n,
      aggregate_function (expression)
    FROM tables
    WHERE conditions
    GROUP BY expression1, expression2, ... expression_n;
    

    SQL 101: Seen are medium and other aggregate data

      SELECT DISTINCT
             comp.company_name || ' - ' || comp.contract_number AS "company_name",
             UPPER (bh.first_name) AS "budget_holder",
             INITCAP (sup.first_name) || ' - ' || sup.surname AS "supervisor",
             INITCAP (emp.status) AS "department",
             INITCAP (emp.first_name || ' ' || emp.surname) AS "employee",
             r.employee_id,
             emp.paaf_number AS "paaf_num",
             emp.employee_payroll_number AS "payroll_num",
             emp.discipline AS "discipline",
             NVL (SUM (tg.week_day1), 0) AS "day1",
             NVL (SUM (tg.week_day2), 0) AS "day2",
             NVL (SUM (tg.week_day3), 0) AS "day3",
             NVL (SUM (tg.week_day4), 0) AS "day4",
             NVL (SUM (tg.week_day5), 0) AS "day5",
             NVL (SUM (tg.week_day6), 0) AS "day6",
             NVL (SUM (tg.week_day7), 0) AS "day7",
             r.valid_from,
             r.valid_to
        FROM tw_roster_data r
             JOIN tw_employee emp
                ON emp.employee_id = r.employee_id
             JOIN tw_timesheet_stage tg
                ON tg.employee_id = r.employee_id
                   AND tg.week_commencing = r.valid_from
             JOIN tw_contracting_company comp
                ON comp.contracting_company_id = r.contracting_company_id
             JOIN tw_supervisor sup
                ON sup.supervisor_id = tg.supervisor_id
             JOIN tw_budget_holder bh
                ON bh.budget_holder_id = sup.budget_holder_id
       WHERE     r.contracting_company_id = 101
             AND r.VALID_FROM = '31-JAN-2015'
             AND r.VALID_TO = '06-FEB-2015'
    GROUP BY
    comp.contract_number
    ,comp.company_name
    ,bh.first_name
    ,sup.first_name
    ,sup.surname
    , emp.status
    ,emp.first_name
    ,emp.surname
    r.employee_id,
    emp.paaf_number,
    emp.employee_payroll_number,
    emp.discipline,
     r.valid_from,
     r.valid_to;
    

Maybe you are looking for