Retrieve last entry for each

IUnknown

I have the following table for evaluating students:

StudentID | EvaluationStatusID| Date
1011010   |      1            |2013-11-07 20:31:51.000
1011020   |      1            |2013-11-08 13:23:51.000
1011010   |      2            |2013-11-08 20:31:51.000
1011020   |      3            |2013-11-09 20:31:51.000

The evaluation of a student does through different stages - 'submitted','assessed,'accepted' etc.

I need to get the LATEST record(by date) on each student in teh form 'StudentID-EvaluationStatusID'.

So,in the above data i should have the following returned:

1011010-2
1011020-3

In Sql server 2008,how do I get this?

Tim Schmelter

The simplest is using ranking functions like ROW_NUMBER.

WITH CTE AS
(
    SELECT StudentID, EvaluationStatusID, Date,
           RN = ROW_NUMBER() OVER (PARTITION BY StudentID
                                   ORDER BY Date DESC)
    FROM dbo.Student
)
SELECT StudentID, EvaluationStatusID, Date
FROM CTE WHERE RN = 1

Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL Query select the last entry of each product

From Dev

Get last entry from each user in database

From Dev

SQL Query select the last entry of each product

From Dev

Getting last entry for each of a distinct column value

From Dev

Retrieve last known value for each column of a row

From Dev

if two or more entry in last column, make independent row for each entry

From Dev

MySQL Select Last Entry for each User, than the next entry

From Dev

SQL Query select last entry for each product and the one previous the last

From Dev

Selecting the last entry of each day in a timestamp and corresponding values

From Dev

Group by Item, showing only the last entry of each group

From Dev

Retrieve only last record of each entity and not all the records

From Dev

How to retrieve the last 30 days of activity for each user since their last activity

From Dev

Linq to SQL - Getting the last know history entry for each divice, prior to a certain date

From Dev

tsql: How to retrieve the last date of each month between given date range

From Dev

Retrieve last non-null record of every column for each record_id in MySQL

From Dev

Retrieve data quarterly(each 3 month) and also show last day of quarter

From Dev

Cron entry for last Saturday

From Dev

How to retrieve last command?

From Dev

Retrieve the author of the last comments

From Dev

Find the most recent entry for each item listed in a log file (e.g. last logged on user in login history)

From Dev

Only the last entry is selected to itab

From Dev

Getting last entry from table

From Dev

Get a value for the last entry of a day

From Dev

Access the last entry of a list with Mustache

From Dev

Find last occurrence of an entry in sql

From Dev

Remove all but last entry by column

From Java

Retrieve last 100 lines logs

From Dev

Retrieve last inserted id with Mysql

From Dev

retrieve last 5 unread messages

Related Related

  1. 1

    SQL Query select the last entry of each product

  2. 2

    Get last entry from each user in database

  3. 3

    SQL Query select the last entry of each product

  4. 4

    Getting last entry for each of a distinct column value

  5. 5

    Retrieve last known value for each column of a row

  6. 6

    if two or more entry in last column, make independent row for each entry

  7. 7

    MySQL Select Last Entry for each User, than the next entry

  8. 8

    SQL Query select last entry for each product and the one previous the last

  9. 9

    Selecting the last entry of each day in a timestamp and corresponding values

  10. 10

    Group by Item, showing only the last entry of each group

  11. 11

    Retrieve only last record of each entity and not all the records

  12. 12

    How to retrieve the last 30 days of activity for each user since their last activity

  13. 13

    Linq to SQL - Getting the last know history entry for each divice, prior to a certain date

  14. 14

    tsql: How to retrieve the last date of each month between given date range

  15. 15

    Retrieve last non-null record of every column for each record_id in MySQL

  16. 16

    Retrieve data quarterly(each 3 month) and also show last day of quarter

  17. 17

    Cron entry for last Saturday

  18. 18

    How to retrieve last command?

  19. 19

    Retrieve the author of the last comments

  20. 20

    Find the most recent entry for each item listed in a log file (e.g. last logged on user in login history)

  21. 21

    Only the last entry is selected to itab

  22. 22

    Getting last entry from table

  23. 23

    Get a value for the last entry of a day

  24. 24

    Access the last entry of a list with Mustache

  25. 25

    Find last occurrence of an entry in sql

  26. 26

    Remove all but last entry by column

  27. 27

    Retrieve last 100 lines logs

  28. 28

    Retrieve last inserted id with Mysql

  29. 29

    retrieve last 5 unread messages

HotTag

Archive