How to get the first and last record

Hai All
I have table called T1 and there are more than 8 lakhs records and i have a column called Timestamp so i need to get the first record value and time stampvalue and last record and time stamp value so that i can conclude that For Example
form 13 june to 15 june data are here
Kind Regards
SrikkanthM

Something like this can also indicate the first and last rows as you query...
SQL> select empno, ename, hiredate
  2        ,case row_number() over (order by hiredate)
  3           when 1 then 'First Row'
  4           when count(*) over () then 'Last Row'
  5         end as flag
  6  from emp;
     EMPNO ENAME      HIREDATE            FLAG
      7369 SMITH      17/12/1980 00:00:00 First Row
      7499 ALLEN      20/02/1981 00:00:00
      7521 WARD       22/02/1981 00:00:00
      7566 JONES      02/04/1981 00:00:00
      7698 BLAKE      01/05/1981 00:00:00
      7782 CLARK      09/06/1981 00:00:00
      7844 TURNER     08/09/1981 00:00:00
      7654 MARTIN     28/09/1981 00:00:00
      7839 KING       17/11/1981 00:00:00
      7900 JAMES      03/12/1981 00:00:00
      7902 FORD       03/12/1981 00:00:00
      7934 MILLER     23/01/1982 00:00:00
      7788 SCOTT      19/04/1987 00:00:00
      7876 ADAMS      23/05/1987 00:00:00 Last Row
14 rows selected.
SQL>

Similar Messages

  • How to show the First and Last name of the user instead of user name

    Gurus,
    We have the full email id of the user as the portal user name. Right now we are using the "Item Attributes - Current User" to show the user name. We don't want to show this anymore. We would like to show the First and Last name of the user on the Portal page. How can i do this. Please post a reply if you have some idea about it.
    Thanks
    Raj
    ---------

    I believe this is possible using the security APIs. See http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/PLSQL/DOC/PLDOC_9026/INDEX.HTML and look for person_info (Returns user information, given a user name)
    under wwsec_api
    Suggest posting any follow-up questions to the Security forum - http://forums.oracle.com/forums/forum.jsp?forum=6

  • How to get the first and the last record of every month within a time range in sql

    I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
    where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
    SELECT PurOrderNum,
    OrderDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to get the first and second quarter from CRT

    Dear Freinds,
                    I have one scenario , the Functional SPEC says Read the payroll results and from the CRT  get all the 4 quaters
    for the wage type /5UH  and sum them and then pass on the to field in the main strucutre.
    Iam using the FM HR_GET_PAYROLL_RESULTS
      CALL FUNCTION 'HR_GET_PAYROLL_RESULTS'
        EXPORTING
          pernr                         = fp_v_pernr
          permo                         = fp_v_permo
          pabrj                         = fp_v_pabrj
          pabrp                         = fp_v_pabrp
          actual                        = 'A'
        TABLES
          result_tab                    = i_payresult
        EXCEPTIONS
          no_results                    = 1
          error_in_currency_conversion  = 2
          t500l_entry_not_found         = 3
          period_mismatch_error         = 4
          t549q_entry_not_found         = 5
          internal_error                = 6
          wrong_structure_of_result_tab = 7
          OTHERS                        = 8.
    Iam collecting all the Actual Result (current result) values
    on the selection screen iam passing for month april (04 2008)
    so this falls in the second quater .
    the internal table   i_payresult is picking up only the second quater (01-04-2008 to 30/04/2008 )  ,but since on the selection screen iam pasing as other period (04 2008) the internal table  i_payresult  returing from the FM  (HR_GET_PAYROLL_RESULTS) only   picks the second quater,
    could any one let meknow how i can pick up the first quarter as well and add the first and second quater to mee the requirement .
    Please help me in this regard
    Thanks & regards
    maduri

    Hi Manoj,
                 Thank you for giving me idea for going further  regarding this problem , so my final question for this is
    as per FS they said they are going to enter the payroll
    area and the other selection as 04 2008 
    In order to achieve the first quarter , because 04 2008 means they are going to enter for the second quarter , the payroll results will come only for second quarter and not for the first quater , if they want to sum all the two quarters then they shouldnt pass on the selection screen   the dates as 04 2008, instead they has to pas
    01 01 2008 to 30 06 2008 , as there is no point in they passing as 04 2008 as we are going to consider from 01 2008 to 062008 .   Please correst me if am correct regarding the dates passing on teh selection screen
    or if the user enters on theslection screen still enter 04 2008 and will be  able to acheive the first quarter ??
    Please answer me this point before i can change the logic of the code and tell to my FO regarding this point.
    thanks & regards
    Madhuri

  • How to compare the first and last characters of strings?

    lets say we have a name column with values;
    c1
    Antu Anamentu
    Steven Smith
    Since A=A and U=U for the first value we need a TRUE and FALSE for the second value SQL. Is this possible to do with REGEXP functions on 10gR2.
    Thank you.

    Hi Frank,
    Just minor correction: REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$') ;
    Explanation: ^(.) =>^ specifies the next char is first char
                                . dot specifies single character
                               ()  defines group which can be backrferenced
                       .* => Any number of characters as we want only first and last character
                      (.)  => (.)space The space signifies that we want to remember last char of first word or char before space
                       \1 => It recalls first group which we saved for backreference using (.)
                       .* => Any number of chars
                      \2 =>  It recalls first group which we saved for backreference using (.)
                       $ => It specifies the char before this is last charHope it clarifies :)
    SQL> WITH t AS
    SELECT 'Antu Anamentu' Name1 FROM DUAL UNION ALL
    SELECT 'Steven Smith' Name1 FROM DUAL
    SELECT Name1
    FROM t
    WHERE REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$')  ;
    NAME1
    Antu Anamentu

  • How to get the first or last row value from a group using ntile

    I want to query and use ntile to divide by data in 4 groups (quartiles). I got this part no problem and it returns the list of rows and the ntile bucket value for each one.
    What I want though is to get only the first row from each ntile group (so in effect the max, q3, median, q1 and min values from the whole result). Of course I coud get max, min and median directly using the other functions, but how about the values for q3 and q1?
    My query contains this:
    NTILE(4) OVER (ORDER BY salary DESC NULLS LAST) as ntile
    So I want the highest, lowest, middle, q3 and q1 values for the salaries.
    Should I be using NTILE, ROWNUM, PERCENTIL_DIST....?
    Any ideas? Thanks in advance.

    SQL> select ename,sal,
      2  NTILE(4) OVER (ORDER BY sal DESC NULLS LAST) as ntile
      3  from emp
      4  /
    ENAME             SAL      NTILE
    KING             5000          1
    FORD             3000          1
    SCOTT            3000          1
    JONES            2975          1
    BLAKE            2850          2
    CLARK            2450          2
    ALLEN            1600          2
    TURNER           1500          2
    MILLER           1300          3
    WARD             1250          3
    MARTIN           1250          3
    ENAME             SAL      NTILE
    ADAMS            1100          4
    JAMES             950          4
    SMITH             800          4
    14 rows selected.
    SQL> select  ename,
      2          sal
      3    from  (
      4           select  ename,
      5                   sal,
      6                   ROW_NUMBER() OVER (PARTITION BY ntile ORDER BY sal DESC NULLS LAST) as rn
      7             from  (
      8                    select  ename,
      9                            sal,
    10                            NTILE(4) OVER (ORDER BY sal DESC NULLS LAST) as ntile
    11                      from  emp
    12                   )
    13          )
    14    where rn = 1
    15  /
    ENAME             SAL
    KING             5000
    BLAKE            2850
    MILLER           1300
    ADAMS            1100
    SQL> SY.

  • How  we claculate the first and last date of the month

    hi,
    I have a requirement, if i have the any date of a month like today date 02/13/2008. So i want the first date of this month and the last date of this month.
    Is there any FM for this..or if you have nay prorgam pls send to me.
    thanks.

    Hi Vipin,
    Try
    HR_JP_MONTH_BEGIN_END_DATE FM will return both first day and last day
    LAST_DAY_OF_MONTHS  for getting last day of month.
    Reward if helpful.
    Regards,
    Mandeep

  • Select first and last records in grouped results - Oracle 11g

    Say I have the following information in an Oracle 11g table:
    Qty
    Production order
    Date and time
    20
    00000000000000001
    12-JAN-14 00:02
    20
    00000000000000001
    12-JAN-14 00:05
    20
    00000000000000001
    12-JAN-14 00:07
    20
    00000000000000001
    13-JAN-14 00:09
    30
    00000000000000002
    12-JAN-14 00:11
    30
    00000000000000002
    12-JAN-14 00:15
    30
    00000000000000002
    12-JAN-14 00:20
    30
    00000000000000002
    14-JAN-14 00:29
    I would like to write a query that would return the following:
    Qty
    Production order
    First
    Last
    80
    00000000000000001
    12-JAN-14 00:02
    13-JAN-14 00:09
    120
    00000000000000002
    12-JAN-14 00:11
    14-JAN-14 00:29
    That is, the sum of the Qty column grouped by Production order, and the date/time of the first and last records for each Production order.
    I came up with a query that yielded this result:
    Qty
    Production order
    First
    Last
    80
    00000000000000001
    12-JAN-14 00:02
    14-JAN-14 00:29
    120
    00000000000000002
    12-JAN-14 00:02
    14-JAN-14 00:29
    Which means that the First and Last columns show the overall first and last date / time of the whole table. Please note that this is a dummy table. Sorry I am now allowed to write the actual query
    I came up with since work policies do not allow me to share it. Also, I tried with windowing functions such as rank()and row_number() but my user does not have enough privileges to do so.
    Any help or hints will be greatly appreciated.

    Due to the fact that Oracle does not record the rows in any particular order, it would be wrong that the "first date" would be the first row processed by the query.
    Therefore you would have to supply some other column if you do not want to consider the table as ordered by date.
    Also, any analytical functions will need you to supply the "order by" and if its the date, then just a simple query will do:
    SQL>WITH Tab1 (Qty, Production_Order, Pdate)
      2       AS (SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:02', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      3           SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:05', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      4           SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:07', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      5           SELECT 20, '00000000000000001', TO_DATE ( '13-JAN-14 00:09', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      6           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:11', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      7           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:15', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      8           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:20', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      9           SELECT 30, '00000000000000002', TO_DATE ( '14-JAN-14 00:29', 'DD-MON-YY HH24:MI') FROM DUAL)
    10  SELECT   SUM ( Qty), Production_Order, MIN ( Pdate), MAX ( Pdate)
    11      FROM Tab1
    12  GROUP BY Production_Order
    13* ORDER BY Production_Order
    SQL> /
      SUM(QTY) PRODUCTION_ORDER     MIN(PDATE)                    MAX(PDATE)
            80 00000000000000001    12-Jan-2014 00:02:00          13-Jan-2014 00:09:00
           120 00000000000000002    12-Jan-2014 00:11:00          14-Jan-2014 00:29:00

  • SQL Selecting the first and last entries for each day

    Hello SQL experts,
    I hope you can help with this.. I have a table (could have 1M or more rows in it) see structure below. I am looking to get the first and last date/times for each employee for each day. I also need the location GUID for the first read.
    EmployeeGUID (uniqueidentifier datatype)
    LocationGUID (uniqueidentifier datatype)
    DateTime (DateTime datatype)
    12345678-0000-0000-0000-000000000000
    11111111-0000-0000-0000-000000000000
    04/12/2014 07:00:01
    12345678-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/12/2014 10:40:05
    12345678-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/12/2014 17:04:02
    44422222-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/14/2014 08:00:00
    44422222-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/14/2014 14:00:03
    44422222-0000-0000-0000-000000000000
    33333333-0000-0000-0000-000000000000
    04/15/2014 07:49:00
    44422222-0000-0000-0000-000000000000
    11111111-0000-0000-0000-000000000000
    04/15/2014 09:00:01
    This would be the ideal output (I can do without the TotalTimeInHours):
    EmployeeGUID (uniqueidentifier datatype)
    LocationGUID (uniqueidentifier datatype)
    FirstRead (DateTime datatype)
    LastRead (DateTime datatype)
    TotalTimeInHours
    12345678-0000-0000-0000-000000000000
    11111111-0000-0000-0000-000000000000
    04/12/2014 07:00:01
    04/12/2014 17:04:02
    Total in hours between the first and last read.
    44422222-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/14/2014 08:00:00
    04/14/2014 14:00:03
    44422222-0000-0000-0000-000000000000
    33333333-0000-0000-0000-000000000000
    04/15/2014 07:49:00
    04/15/2014 09:00:01
    I would post what I have tried so far but I have been trying many different types of queries over the last few days. In short I need the employees first and last reads for each date. They could have many entries per date or just 1. I am certain that this
    is a trivial thing for a SQL expert but not trivial for me :).
    Thank you in advance!

    Thank you!
    This is almost what I need. The LocationGUID has to be included in the output. When I include it, I have to put it in the Group By clause. When I do that the reads are based on the LocationGUID (see below).
    ** I added a few more data entries and included the LocationGUID in the output.
    ***** SQL ***********
    CREATE TABLE test(  EmployeeGUID  uniqueidentifier, LocationGUID  uniqueidentifier, DateTimeCol  DateTime )Insert into test values
    ('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/12/2014 07:00:01')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 10:40:05')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 17:04:02')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 19:00:00')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 08:00:00')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 14:04:03')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 07:49:00')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 09:00:01')
    ,('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/13/2014 10:40:05')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 17:04:02')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 19:00:00')
    ;with mycte as (
    SELECT *, row_number() OVER(partition by EmployeeGUID, Cast(DateTimeCol as date)  Order by  DateTimeCol) rnASC,
     row_number() OVER (partition by EmployeeGUID, Cast(DateTimeCol as date)  Order by  DateTimeCol DESC) rnDESC
    FROM    test)
    Select EmployeeGUID ,Cast(DateTimeCol as date) dt,LocationGUID,
    Max(Case when rnASC=1 Then DateTimeCol End) minDateTimeCol
    ,Max(Case when rnDESC=1 Then DateTimeCol End ) maxDateTimeCol
    ,Datediff(minute, Max(Case when rnASC=1 Then DateTimeCol End) ,Max(Case when rnDESC=1 Then DateTimeCol End ) )/60.0  TotalTimeInHours
    from mycte
    Group by EmployeeGUID, LocationGUID,Cast(DateTimeCol as date)
    Order by dt,EmployeeGUID
    drop TABLE test
    **** OUTPUT **********
    EmployeeGUID
    dt
    LocationGUID
    minDateTimeCol
    maxDateTimeCol
    TotalTimeInHours
    12345678-0000-0000-0000-000000000000
    2014-04-12
    11111111-0000-0000-0000-000000000000
    2014-04-12 07:00:01.000
    NULL
    NULL
    12345678-0000-0000-0000-000000000000
    2014-04-12
    22222222-0000-0000-0000-000000000000
    NULL
    2014-04-12 19:00:00.000
    NULL
    12345678-0000-0000-0000-000000000000
    2014-04-13
    11111111-0000-0000-0000-000000000000
    2014-04-13 10:40:05.000
    NULL
    NULL
    12345678-0000-0000-0000-000000000000
    2014-04-13
    22222222-0000-0000-0000-000000000000
    NULL
    2014-04-13 19:00:00.000
    NULL
    44422222-0000-0000-0000-000000000000
    2014-04-14
    22222222-0000-0000-0000-000000000000
    2014-04-14 08:00:00.000
    2014-04-14 14:04:03.000
    6.066666

  • How can I display the first and last name using a paramater as employee ID?

    Hi SAP,
    I have a parameter that is called {? Employee ID}.   What I want to do is display the first and last name based on the employee ID value entered in {? Employee ID} in the page header of the report.  Right now, when I put the following formula in the page header only some pages get the right result while other pages dont....
    if table.employeeid = {? Employee ID} then
    table.firstname" "table.lastname
    It appears as though if the first record in the details section on the beginning of each page happens to be the employee under {? Employee ID} then it prints it correctly, if it isn't I get a null value in the page header.
    Anyone have any ideas?
    Z

    Hi Try this,
    Whileprintingrecords;
    if ={?EmpID} then
    Also check the option "Default values for null" in the formula editor.
    Regards,
    Vinay

  • How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, how do I select the first and last message and delete everything in between?

    How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, what do I select if I mark the first and last email to delete everything in between? Thanks.

    I have this same issue. I have over 100 email addresses that I need to add to a group. The issue is not making the group, it's getting the email addresses from Mail to Contacts.
    Dragging the email addresses does nothing. You can copy the addresses, but there's nowhere to put them. You can make a VCF for an email address, but then you have to find all of them to add them to the group. How do you automate this?!
    I'm astounded that there's so little support for such a common issue for which people have been asking for years.

  • Get the first and the last date of a week

    Hi all
    I need to get the first and the last date of a specific week.
    I need a function that returns two date passing it just one date.
    The function has to calculate the first and the last date of the week of the argument date.
    hope to be clear
    regards

    goiters,
    I need to get the first and the last date of a specific week.Yup, and what's the first day of the week in your part of the world, is it Sunday or Monday?
    I need a function that returns two date passing it just one date.No you don't, just add 7 days to the start of the week.
    hope to be clearWell, you can hope.
    Keith.
    Message was edited by: corlettk - now I hope to clear ;-)

  • How to view the first and the last frame of a clip or a selected range in the time line?

    How to view the first and the last frame of a clip directly or in a selected range in the time line ? Up arrow and down arrow keys changes only between the first frame of the consecutive clips. Even ; and ' does the same. I mean what is the shortcut keys for first to last and last to first frame of a clip? Help please.

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Format first and last record of result query

    Hello
    I have the following query
    <tt>select 1 seq, 'This is First record' data from dual union all
    select 2, 'Data ' || tname from tab union all
    select 3, 'This was last record Last record' from dual
    order by 1</tt>
    When i spool this statement to a listfile with col seq noprint option i get:
    This is First record
    Data MLA_ACCESS_LIST
    Data MLA_APPLICATIONS
    Data MLA_VPD_PCK
    Data MLA_VPD_TABLES
    This was last record Last record
    But i want:
    This is First record MLA_ACCESS_LIST
    Data MLA_APPLICATIONS
    Data MLA_VPD_PCK
    MLA_VPD_TABLES This was last record Last record
    I tried it with 1 statement with usage of lead and lag, because first and last record have to differ from the other result records. But i get ORA-30484: missing window specification for this function
    Is this possible with 1 statement or am i doomed to edit the results by myself?
    Thanks Auke

    select case row_number() over (order by tname)
    when 1 then 'This is the First record '
    end || tname ||
    case row_number() over (order by tname desc)
    when 1 then ' This was the last record'
    end
    from tab
    order by tname
    hth

  • First and Last Record

    Hi everybody,
    I have problem with first and last record.How can I specified that current record is first and last record.
    it means that is any statement exist that determine :System.first_record is equal to :System.last_record.
    It's very emergancy.
    Thanks for your attention and your help.
    /Shiva

    You can try this:
    if :system.cursor_record = '1' and :system.last_record = 'TRUE' then
    -- this is the only record in block
    end if;
    Hi everybody,
    I have problem with first and last record.How can I specified that current record is first and last record.
    it means that is any statement exist that determine :System.first_record is equal to :System.last_record.
    It's very emergancy.
    Thanks for your attention and your help.
    /Shiva

Maybe you are looking for