20 August 2018 · n-pacha ·       Add to Favorites   Report

How to fetch a sample of data within each group - Teradata

Scenario: We need to select a random sample of 5 in each status type

TABLE1

MEMBERSTATUS
89A
34A
25R
27S
69J
32R
39J
55S
32A

Solution:

SEL     Member, status 
FROM    TABLE1 
QUALIFY ROW_NUMBER() OVER (
            PARTITION BY status 
            ORDER BY NULL) <= 50;


n-pacha

posted on 20 August 2018

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied