Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 03 Dec 2004 @ 15:51:55 GMT


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


Subj:   Re: Best way of writing SQL to retrieve a sample
 
From:   Michael Larkins

Although a function like RANK will work for this, it is not a random sample. Instead, it will always return the highest values or optional the lowest values. Plus, you did not tell us which release of Teradata you are running, so here a way to get a random sampling in both V2R4 and V2R5:

     sel country_code, state_code, county_code
     from (sel country_code, state_code, county_code, csum(1,1) as randomizer
            from country_table   group by 1  qualify randomizer < 51) DerivedTable

If you have V2R5 and prefer ANSI standard SQL, you should be able to do the same thing with ROW_NUMBER.


Hope this helps,

Michael Larkins
Certified Teradata Master
Certified Teradata SQL Instructor



     
  <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: 15 Jun 2023