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
↧