Skip to Main Content

Write Great SQL Office Hours

Free tips and training every month! Subscribe for reminders and more from Office Hours. FAQ

Header container

September 21, 2021

13:00 UTC   Start Times Around the World

Subscribe to be notified of changes to sessions and give us feedback!

Having trouble watching the video on this page? Open the video in your browser.

Description

Splitting rows into buckets with SQL
Often you want to split rows into consistent groups of equal size or range. For example, to create histograms, compare periods or view spread in data

Join this session to learn how you can use

NTILE to create groups with an equal number of rows
WIDTH_BUCKET to make each group cover an equal range of values
Formulas to define fixed ranges

Highlights from this session include:

02:30 - Splitting rows into quartiles using NTILE
06:30 - Creating histograms with equal-sized intervals using WIDTH_BUCKET
10:00 - Group strings together by starting letter with WIDTH_BUCKET
13:00 - Demo of using NTILE
15:30 - Demo of using WIDTH_BUCKET
22:00 - Demo of ways to group character values
27:30 - Recap of differences between NTILE and WIDTH_BUCKET
31:40 - Grouping rows into 5-minute intervals
33:20 - Demo of splitting data into groups of five rows each
35:45 - Demo of grouping rows in 5-minute intervals
42:30 - Demo of RATIO_TO_REPORT
44:45 - Review of different ways to group rows into "consistent" sized bins

Get the scripts for this session https://livesql.oracle.com/apex/livesql/file/content_MD0J8KLQAKL6SOC2UGNCC3VSR.h tml

Practice your SQL skills with free quizzes https://devgym.oracle.com/pls/apex/dg/competition/sql

Your Experts

  • #SELECTION#
    Chris Saxon

    Chris Saxon   

    Chris Saxon is an Oracle Developer Advocate and quizmaster on Dev Gym. His job is to help you get the best out of the Oracle Database and have fun with SQL! He's also part of the answer team on Ask TOM and creates YouTube videos at The Magic of SQL channel.
    #MISC#
    #ACTIONS#