vendredi 26 octobre 2018

SQL Random Sample With Case When Statement

I need to write a query that will return a random sample of records. But I must able to specify the sample size based on the value of one field.

This is a simplified version of the query I'm working on. In this example I need to return a total of 300 records, 100 where tier = 1 and 200 where tier =2.

I'm not sure if this is possible with the Sample feature.

 SELECT 
 ID,
 TIER

 FROM TIERTABLE a

 SAMPLE CASE WHEN TIER = 1 
 THEN 100
 WHEN TIER = 2
 THEN 200 END 




Aucun commentaire:

Enregistrer un commentaire