Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Getting a dynamic Sample - response (3) by dnoeth

$
0
0
How large is this table? OLAP functions are more expensive than RANDOM or SAMPLE but you could do it like this: SELECT * FROM tab QUALIFY ROW_NUMBER() OVER (PARTITION BY communication_id ORDER BY HASHROW(xxx)) <= 10 -- at least 10 rows OR (ROW_NUMBER() OVER (PARTITION BY communication_id ORDER BY HASHROW(xxx)) <= COUNT(*) OVER (PARTITION BY communication_id) / 10 -- 10 percent of the rows AND ROW_NUMBER() OVER (PARTITION BY communication_id ORDER BY HASHROW(xxx)) <= 100) -- maximum of 100 rows As RANDOM can't be used within an OLAP function xxx must be a column which is (close to) unique. Instead of HASHROW(xxx) you could simply use "1", but this will probably result in skewed spool.   Dieter

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>