The mean and standard deviation do not tell the whole story of a distribution. Booking amounts have many small values and a long tail of large ones; a symmetric distribution looks very different. Skewness measures that lopsidedness, and kurtosis how heavy the tails are. Oracle computes both as aggregate functions.
Code for This Guide
The main examples are in the examples/aggregate-functions folder of the Oracle Database 26ai code repository on GitHub, each with its output. They use NIMBUS, the sample schema of a fictional airline, which you can install with the scripts in the setup/nimbus folder.
They come from Oracle Database 26ai SQL and PL/SQL Book.
Syntax
Syntax:
skewness_pop(expr) skewness_samp(expr) kurtosis_pop(expr) kurtosis_samp(expr)
| Result | Meaning |
|---|---|
| Skewness near 0 | Roughly symmetric |
| Skewness above 0 | A long tail of high values (right-skewed) |
| Skewness below 0 | A long tail of low values (left-skewed) |
| Higher kurtosis | Heavier tails: extreme values are more common |
The _POP versions treat the data as a whole population, the _SAMP versions as a sample.
Booking Amounts
Example:
select round(skewness_pop(total_amount), 3) as skew_pop,
round(skewness_samp(total_amount), 3) as skew_samp,
round(kurtosis_pop(total_amount), 3) as kurt_pop,
round(kurtosis_samp(total_amount), 3) as kurt_samp
from bookings;Output:
SKEW_POP SKEW_SAMP KURT_POP KURT_SAMP
___________ ____________ ___________ ____________
2.652 2.658 7.921 7.986A skewness of about 2.65 means a strong right tail: a few business-class trips cost many times the typical economy booking. A kurtosis near 8 means those extreme values are common: the tails are heavy.
Per Cabin
Example:
select cabin, count(*) as tickets, round(avg(fare)) as avg_fare, round(median(fare)) as median_fare,
round(skewness_samp(fare), 3) as skewness, round(kurtosis_samp(fare), 3) as kurtosis
from tickets
group by cabin;Output:
CABIN TICKETS AVG_FARE MEDIAN_FARE SKEWNESS KURTOSIS ___________ __________ ___________ ______________ ___________ ___________ BUSINESS 270 2290 1980 0.842 -0.308 ECONOMY 799 641 544 0.727 -0.473
Within each cabin, fares are only mildly skewed (0.84 and 0.73) and have much lighter tails. Most of the skewness of all bookings comes from mixing the two cabins, which is also why the median is below the average in each.
Things to Know
- Skewness and kurtosis need enough data to be meaningful; on a handful of rows they vary a lot.
- For skewed data, report the median alongside the average.
- They work as analytic functions with OVER as well.
Related Guides
Conclusion
SKEWNESS_POP and SKEWNESS_SAMP measure how lopsided a distribution is, and KURTOSIS_POP and KURTOSIS_SAMP how heavy its tails are. Use them to describe the shape of data beyond its mean and spread, and compute them per group to see whether skew comes from mixing groups.
