Look up critical values and label each hypothesis test reject or accept in SQL

Quick Overview

Write a SQL query that joins each hypothesis test to a critical value lookup table on degrees of freedom and significance level, then labels it reject or accept. It tests composite-key joins, CASE logic at a strict boundary, deterministic ordering and how a decision rule maps to the test's tail.

Look up critical values and label each hypothesis test reject or accept in SQL

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Each row of `test_results` is one hypothesis test, with its test statistic, degrees of freedom and significance level. A seeded lookup table, `critical_values`, holds the critical value for each combination of `df` and `alpha`. Join every test to its critical value on `df` and `alpha`, and label the test `'reject'` when `test_statistic` is strictly greater than `critical_value`, otherwise `'accept'`. ### Input Table(s) `test_results` | Column | Type | Meaning | |---|---|---| | test_statistic | DECIMAL(8,3) | Observed value of the test statistic | | df | INT | Degrees of freedom of the test | | alpha | DECIMAL(4,3) | Significance level, either 0.05 or 0.01 | Each row is one test. The table has no key column, and two tests may share the same values. `critical_values` | Column | Type | Meaning | |---|---|---| | df | INT | Degrees of freedom | | alpha | DECIMAL(4,3) | Significance level | | critical_value | DECIMAL(8,4) | Threshold the statistic must exceed to reject | Primary key: (`df`, `alpha`). ### Output Contract One row per row of `test_results`, with these columns in this order: | Column | Definition | |---|---| | test_statistic | From `test_results` | | df | From `test_results` | | alpha | From `test_results` | | critical_value | The matching value from `critical_values` | | decision | `'reject'` if `test_statistic > critical_value`, else `'accept'` | Return the numeric columns as stored, without rounding. Sort by `df` ascending, then `alpha` ascending, then `test_statistic` ascending. ### Example Input `test_results`: | test_statistic | df | alpha | |---|---|---| | 2.93 | 4 | 0.05 | | 3.188 | 4 | 0.01 | | 8.4 | 3 | 0.01 | | 13.909 | 3 | 0.01 | | 4.998 | 2 | 0.01 | | 2.676 | 1 | 0.01 | | 9.061 | 2 | 0.05 | Input `critical_values`: | df | alpha | critical_value | |---|---|---| | 1 | 0.05 | 3.841 | | 1 | 0.01 | 6.635 | | 2 | 0.05 | 5.991 | | 2 | 0.01 | 9.21 | | 3 | 0.05 | 7.815 | | 3 | 0.01 | 11.345 | | 4 | 0.05 | 9.488 | | 4 | 0.01 | 13.277 | Expected result: | test_statistic | df | alpha | critical_value | decision | |---|---|---|---|---| | 2.676 | 1 | 0.01 | 6.635 | accept | | 4.998 | 2 | 0.01 | 9.21 | accept | | 9.061 | 2 | 0.05 | 5.991 | reject | | 8.4 | 3 | 0.01 | 11.345 | accept | | 13.909 | 3 | 0.01 | 11.345 | reject | | 3.188 | 4 | 0.01 | 13.277 | accept | | 2.93 | 4 | 0.05 | 9.488 | accept | Only two tests clear their thresholds: 9.061 is above 5.991 (df 2, alpha 0.05) and 13.909 is above 11.345 (df 3, alpha 0.01). Every other statistic is below its critical value. ### Constraints and Clarifications - Every (`df`, `alpha`) pair in `test_results` has exactly one row in `critical_values`. - No column in either table is NULL. - A statistic exactly equal to its critical value is labeled `'accept'`, because rejection requires strictly greater. - Duplicate rows in `test_results` are separate tests and each appears in the output. ```hint Check the boundary Decide what your comparison does when the statistic equals the critical value exactly, and compare that with the rule in the task. ```

Overview: Write a SQL query that joins each hypothesis test to a critical value lookup table on degrees of freedom and significance level, then labels it reject or accept. It tests composite-key joins, CASE logic at a strict boundary, deterministic ordering and how a decision rule maps to the test's tail.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Each row of test_results is one hypothesis test, with its test statistic, degrees of freedom and significance level. A seeded lookup table, critical_values, holds the critical value for each combination of df and alpha. Join every test to its critical value on df and alpha, and label the test 'reject' when test_statistic is strictly greater than critical_value, otherwise 'accept'.

Input Table(s)

test_results

ColumnTypeMeaning
test_statisticDECIMAL(8,3)Observed value of the test statistic
dfINTDegrees of freedom of the test
alphaDECIMAL(4,3)Significance level, either 0.05 or 0.01

Each row is one test. The table has no key column, and two tests may share the same values.

critical_values

ColumnTypeMeaning
dfINTDegrees of freedom
alphaDECIMAL(4,3)Significance level
critical_valueDECIMAL(8,4)Threshold the statistic must exceed to reject

Primary key: (df, alpha).

Output Contract

One row per row of test_results, with these columns in this order:

ColumnDefinition
test_statisticFrom test_results
dfFrom test_results
alphaFrom test_results
critical_valueThe matching value from critical_values
decision'reject' if test_statistic > critical_value, else 'accept'

Return the numeric columns as stored, without rounding. Sort by df ascending, then alpha ascending, then test_statistic ascending.

Example

Input test_results:

test_statisticdfalpha
2.9340.05
3.18840.01
8.430.01
13.90930.01
4.99820.01
2.67610.01
9.06120.05

Input critical_values:

dfalphacritical_value
10.053.841
10.016.635
20.055.991
20.019.21
30.057.815
30.0111.345
40.059.488
40.0113.277

Expected result:

test_statisticdfalphacritical_valuedecision
2.67610.016.635accept
4.99820.019.21accept
9.06120.055.991reject
8.430.0111.345accept
13.90930.0111.345reject
3.18840.0113.277accept
2.9340.059.488accept

Only two tests clear their thresholds: 9.061 is above 5.991 (df 2, alpha 0.05) and 13.909 is above 11.345 (df 3, alpha 0.01). Every other statistic is below its critical value.

Constraints and Clarifications

  • Every ( df , alpha ) pair in test_results has exactly one row in critical_values .
  • No column in either table is NULL.
  • A statistic exactly equal to its critical value is labeled 'accept' , because rejection requires strictly greater.
  • Duplicate rows in test_results are separate tests and each appears in the output.