Skip to Content
0
Former Member
Jul 07, 2016 at 12:09 PM

HANA SQL Select Top Distinct Values

7453 Views

SQL Experts,

I have a table with fields and values.

(This is a timesheet table and the workitem is the code on which the time was logged.)

ID (Key) WORKITEM ENTRYDATE ENTRYTIME

1 ITEM_1 2016-01-01 14:00

2 ITEM_1 2016-01-01 14:00

3 ITEM_1 2016-01-01 14:00

4 ITEM_2 2016-01-02 14:00

5 ITEM_8 2016-01-02 14:00

6 ITEM_3 2016-01-02 14:00

7 ITEM_4 2016-01-03 14:00

8 ITEM_8 2016-01-03 14:00

9 ITEM_8 2016-01-03 14:00

10 ITEM_9 2016-01-04 14:00

I would need the last 5 unique workitems that were used, in an SQL Select.

Can anybody help with this because I tried a select distinct with a sort on entry date + time descending but this did not give me the correct result.

The expected result here would be:

ITEM_9

ITEM_8

ITEM_4

ITEM_3

ITEM_2

Thanks in advance