# Statistical SQL functions for performing t-test

• Script Name Statistical SQL functions for performing t-test
• Description Statistical SQL functions for performing t-test in-Database using the SH.Sales and SH.Customers tables. The t-test measures the significance of a difference of means. You can use it to compare the means of two groups or the means of one group with a constant. A t-test is any statistical hypothesis test in which the test statistic follows a Student's t-distribution under the null hypothesis. It can be used to determine if two sets of data are significantly different from each other, and is most commonly applied when the test statistic would follow a normal distribution if the value of a scaling term in the test statistic were known. When the scaling term is unknown and is replaced by an estimate based on the data, the test statistic (under certain conditions) follows a Student's t distribution. See https://en.wikipedia.org/wiki/Student%27s_t-test
• Category SQL General / Statistical Functions
• Contributor Charlie Berger (Oracle)
• Created Wednesday March 23, 2016
• Statement 1
Query compares the mean of AMOUNT_SOLD between MEN and WOMEN within CUST_INCOME_LEVEL ranges. Returns observed t value and its related two-sided significance See http://docs.oracle.com/database/121/SQLRF/functions191.htm#SQLRF06323 for Documentation. See http://www.oracle.com/technetwork/middleware/index-092760.html for SQL Statistical Functions on OTN.

SQL_t-Test_Function

``````SELECT substr(cust_income_level,1,22) income_level,
avg(decode(cust_gender,'M',amount_sold,null)) sold_to_men,
avg(decode(cust_gender,'F',amount_sold,null)) sold_to_women,
stats_t_test_indep(cust_gender, amount_sold, 'STATISTIC','F') t_observed,
stats_t_test_indep(cust_gender, amount_sold) two_sided_p_value
FROM sh.customers c, sh.sales s
WHERE c.cust_id=s.cust_id
GROUP BY rollup(cust_income_level)
ORDER BY 1``````