Inspect a bounded sample of values

Use SAMPLE to inspect a small set before writing an aggregate query. It returns sampled values, not an estimate with an error bound. Compare it with the full row count.

CREATE DATABASE cookbook_sample;
CREATE TABLE cookbook_sample.readings(id INT, value INT);
INSERT INTO cookbook_sample.readings VALUES(1,10),(2,20),(3,30),(4,40),(5,50);
SELECT COUNT(*) AS total_rows FROM cookbook_sample.readings;
SELECT SAMPLE(value, 3 ROWS) AS sampled_values FROM cookbook_sample.readings;
DROP DATABASE cookbook_sample;

The full table contains five rows; SAMPLE(value, 3 ROWS) returns at most three sampled values. Their identities can vary, so do not use this output as a deterministic top-three or as an exact average. See the v4.2.4 source test.