Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 19 Aug 2010 @ 21:18:16 GMT


     
  <Prev Next>  
<<First
<Prev
Next> Last>>  


Subj:   Minimum values to represent the source set query
 
From:   Padarthi,Hanumath

Hi,

     RPTID   BM
     121     A
     121     B
     122     C
     122     D
     123     B
     123     D
     124     A
     124     B
     125     C
     126     A
     126     C
     126     D

I have the above table with two columns, now I need the minimum BM values to represent all RPTID. In this case B and C

     B   121   123   124
     C   122   125   126

I tried to give a rank by partition by RPT_ID and order by BM then used where RNK=1

     SELECT BM
     ROW_NUMBER()  OVER(PARTITION BY RPT_ID ORDER BY BKMRK_NM) RNK  FROM TABLE WHERE RNK=1

Which should results the same result set as source table when plug into the below query

     SELECT * FROM  WHERE BM IN (SELECT BM
     ROW_NUMBER()  OVER(PARTITION BY RPT_ID ORDER BY BKMRK_NM) RNK  FROM TABLE WHERE RNK=1)

It gives ABC but looking at the data BC would be more optimal. I need algorithm or query to result B and C are minimum BM to represent all RPT_ID


Regards,

Hanumath



     
  <Prev Next>  
<<First
<Prev
Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 27 Dec 2016