Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Selecting a column based on DATE along with GROUP BY - forum topic by pavan.polish

$
0
0

Hi All,

I have a below requirement:-

I have data as below

GID - MID - UID - DATE
1000000 - 1000001 - 9000001 - 2013-11-01
1000000 - 1000002 - 9000002 - 2013-11-21
1000000 - 1000003 - 9000003 - 2013-11-11
1000000 - 1000004 - 9000004 - 2013-11-12

I want to assign GID as UID with highest DATE to all MIDs group by GID.

In this case, UID 9000002 is having highest DATE and this should be assigned as GID.

Hence, my output should be looks like below:-

GID - MID
9000002 - 1000001
9000002 - 1000002
9000002 - 1000003
9000002 - 1000004

I know that this can be achieved by selecting UID of highest DATE and join to the original table to assign it as GID.

Is there any other way this can be achieved in a simplest way.

Thanks a lot in advance.

Sagar.

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>