Oracle 23ai adds four new statistical aggregate functions that give SQL developers direct access to distribution shape analysis without leaving the database.
SKEWNESS_POP and SKEWNESS_SAMP
Skewness measures the asymmetry of a distribution around its mean.
- Positive skew: long tail on the right (e.g., most employees earn average salaries, but a few earn very high)
- Negative skew: long tail on the left
- Zero: symmetric distribution
SELECT
department_id,
ROUND(SKEWNESS_POP(salary), 4) AS pop_skewness,
ROUND(SKEWNESS_SAMP(salary), 4) AS sample_skewness,
COUNT(*) AS headcount
FROM employees
GROUP BY department_id
ORDER BY ABS(SKEWNESS_SAMP(salary)) DESC;
Use SKEWNESS_POP when you have the full population. Use SKEWNESS_SAMP when working with a sample (applies Bessel’s correction).
KURTOSIS_POP and KURTOSIS_SAMP
Kurtosis measures the “tailedness” of a distribution — whether extreme values are frequent or rare compared to a normal distribution.
SELECT
product_category,
ROUND(KURTOSIS_SAMP(order_value), 4) AS kurtosis,
STDDEV(order_value) AS std_deviation,
AVG(order_value) AS mean_value
FROM orders
GROUP BY product_category
HAVING COUNT(*) > 100; -- meaningful only with sufficient data
High kurtosis means more extreme outliers than expected. This is important for financial risk modeling, anomaly detection, and capacity planning.
Before 23ai: You had to calculate skewness and kurtosis manually using complex expressions involving SUM(POWER(x - mean, 3)) and normalization factors. Or export data to Python/R. Now it’s a single function call in SQL, composable with GROUP BY and window functions.
