Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Last occurrence of a key
Wed, Apr 4 2012 9:06 AMPermanent Link

Jose Eduardo Helminsky

HPro Informatica

Table structure

EMP (Integer)
DAT (Date)
SEQ (Integer)
Other fields

Data sample:

EMP  DAT             SEQ
1        2012-03-01   1
1        2012-03-01   2
1        2012-03-01   3 *
1        2012-03-02    1
1        2012-03-02    2 *
1        2012-03-03    1 *

I would like to get the last occurrence of the last the key EMP + DAT + SEQ
(the records with *)

With the following SQL I get the keys but I need the "other fields".
How can I do that ?

select emp,dat,max(seq) from table group by emp,dat

Eduardo

Wed, Apr 4 2012 1:38 PMPermanent Link

John Hay

Eduardo
> Table structure
>
> EMP (Integer)
> DAT (Date)
> SEQ (Integer)
> Other fields
>
> Data sample:
>
> EMP  DAT             SEQ
> 1        2012-03-01   1
> 1        2012-03-01   2
> 1        2012-03-01   3 *
> 1        2012-03-02    1
> 1        2012-03-02    2 *
> 1        2012-03-03    1 *
>
> I would like to get the last occurrence of the last the key EMP + DAT + SEQ
> (the records with *)

One way would be to do it in 2 stages with a script eg

select emp,dat,max(seq) as seq into memory\temp from table group by emp,dat;
select emp,dat,seq,otherfields from memory\temp join table on temp.emp=table.emp and temp.dat=table.dat and
temp.seq=table.seq

John

Thu, Apr 5 2012 5:56 AMPermanent Link

Jose Eduardo Helminsky

HPro Informatica

John

Thanks for your tip.

Eduardo

Image