0
0
PostgreSQLquery~10 mins

TABLESAMPLE for random sampling in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select a random 10% sample of rows from the table named employees.

PostgreSQL
SELECT * FROM employees TABLESAMPLE [1] (10);
Drag options to blanks, or click blank then click option'
ASYSTEM
BRANDOM
CBERNOULLI
DHASH
Attempts:
3 left
💡 Hint
Common Mistakes
Using RANDOM which is not a valid TABLESAMPLE method in PostgreSQL.
Using BERNOULLI which is valid but less efficient than SYSTEM.
2fill in blank
medium

Complete the code to select a 5% random sample of rows using the BERNOULLI method.

PostgreSQL
SELECT * FROM sales TABLESAMPLE [1] (5);
Drag options to blanks, or click blank then click option'
AHASH
BRANDOM
CSYSTEM
DBERNOULLI
Attempts:
3 left
💡 Hint
Common Mistakes
Using SYSTEM which samples pages, not rows.
Using RANDOM which is not a valid method.
3fill in blank
hard

Fix the error in the code to correctly sample 20% of rows from the products table.

PostgreSQL
SELECT * FROM products TABLESAMPLE [1] (20);
Drag options to blanks, or click blank then click option'
ARANDOM
BSYSTEM
CBERNOULLI
DHASH
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses around the percentage.
Using an invalid method name.
4fill in blank
hard

Fill both blanks to select a 15% random sample of rows from the orders table using the BERNOULLI method.

PostgreSQL
SELECT * FROM orders TABLESAMPLE [1] ([2]);
Drag options to blanks, or click blank then click option'
ABERNOULLI
B10
C15
DSYSTEM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SYSTEM instead of BERNOULLI.
Using 10 instead of 15 for the percentage.
5fill in blank
hard

Fill all three blanks to select a 25% random sample of rows from the customers table using the SYSTEM method.

PostgreSQL
SELECT * FROM customers TABLESAMPLE [1] ([2]) REPEATABLE ([3]);
Drag options to blanks, or click blank then click option'
ABERNOULLI
BSYSTEM
C25
D12345
Attempts:
3 left
💡 Hint
Common Mistakes
Using BERNOULLI instead of SYSTEM.
Omitting the REPEATABLE clause or seed value.