Question : Earliest Date of Balance Change for Multiple ID's

I have a table I'm working with that looks like this:

ASSET_ID      CURR_UPB      HIST_UPD_DATE
130000723      500000      7/7/2010
130000723      500000      7/8/2010
130000723      500000      7/9/2010
130000723      500000      7/10/2010
130000723      40000      7/11/2010
130000723      40000      7/12/2010
130000723      40000      7/13/2010
130000723      40000      7/14/2010
130000723      20000      7/15/2010
130000723      20000      7/16/2010
400028174      100000      7/10/2010
400028174      100000      7/11/2010
400028174      100000      7/12/2010
400028174      90000      7/13/2010
400028174      90000      7/14/2010
400028174      90000      7/15/2010
400028174      60000      7/16/2010

I'm trying to write a query that will return
The ID,
The ID's Balance at the earliest date of change,
and the ID's Date of Change.

For instance, using this example,
the results would look like this.

ASSET_ID      CURR_UPB      HIST_UPD_DATE
130000723      500000      7/7/2010      
130000723      40000      7/11/2010      
130000723      20000      7/15/2010      
400028174      100000      7/10/2010      
400028174      90000      7/13/2010      
400028174      60000      7/16/2010      

Thanks,
-JW

Answer : Earliest Date of Balance Change for Multiple ID's

the above will give you duplicates if you have something like this

130000723      500000      7/7/2010

130000723      500000      7/7/2010

130000723      500000      7/8/2010

 

try the code below

1:
2:
3:
4:
5:
select * from (
	select asset_id, curr_upb, hist_upd_date, row_number() over (partition by asset_id, curr_upb order by hist_upd_date) rn
	from yourtable
) a
where rn = 1
Random Solutions  
 
programming4us programming4us