return only to your last move of each code

Asked

Viewed 35 times

1

A table records the movement of items by item code, date and time of movement.

So the presentation is as follows:

CD_Item | DT_Mov
  15      10/04/2018 08:52:36
  15      21/05/2018 09:32:10
  15      20/05/2018 14:24:08
  15      10/04/2018 08:52:36
  08      26/05/2018 09:32:10
  08      27/05/2018 14:24:08
  69      16/05/2018 09:32:10
  69      20/05/2018 14:24:08

I want to make a select to pick up all the items, but let it return me only to your last move of each code.

Upshot:

CD_Item | DT_Mov
   15     21/05/2018 09:32:10
   08     27/05/2018 14:24:08
   69     20/05/2018 14:24:08

The bank is Oracle.

I researched other questions of the kind suggested by the forum itself, but they did not give me a solution.

1 answer

1


If the table structure is the one you’ve pasted, it’s enough:

Select
    cd_item,
    max(dt_mov) as ultima_data
from movimentacao
group by cd_item
  • It worked, I was grouping with the date too and I never went...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.