← Back to Blog

SQL for Lottery Analysis, Part 5: Why None of It Predicts

December 2, 2026  ·  10 min read  ·  Education

SQL for Lottery Analysis series

  1. Part 1: Count how often each number is drawn
  2. Part 2: Find "overdue" numbers with window functions
  3. Part 3: Measure jackpot rollover streaks
  4. Part 4: Same number, same day, different states
  5. Part 5: Test it all: why none of it predicts a draw (you are here)

Free practice data: SQLite database · Powerball CSV · Pick 3/Pick 4 CSV

The first four parts measured the past: which numbers came up most, which have gone quiet, how long jackpots run and how often states match. The natural next question is whether any of it helps predict the next draw. This part tests that directly in SQL, on the same sample database. The answer is no, and the queries show why.

Step 1: Recreate the white_balls view

CREATE VIEW IF NOT EXISTS white_balls AS
SELECT draw_date, n1 AS ball FROM powerball_draws
UNION ALL SELECT draw_date, n2 FROM powerball_draws
UNION ALL SELECT draw_date, n3 FROM powerball_draws
UNION ALL SELECT draw_date, n4 FROM powerball_draws
UNION ALL SELECT draw_date, n5 FROM powerball_draws;

Test 1: Is the frequency spread unusual?

Part 1 found white-ball counts from 80 to 128, against an expected 104.3 each. The standard check for "do these counts fit equal chances?" is the chi-square goodness-of-fit test (NIST). For each ball, take the difference between observed and expected, square it, divide by the expected count, and add up all 69 results. SQL does it in one query:

WITH counts AS (
  SELECT ball, COUNT(*) AS observed
  FROM white_balls
  GROUP BY ball
),
expected AS (
  SELECT COUNT(*) * 5.0 / 69 AS e
  FROM powerball_draws
)
SELECT COUNT(*) AS balls,
       ROUND(SUM((observed - e) * (observed - e) / e), 1) AS chi_square
FROM counts, expected;

Result:

ballschi_square
6974.9

With 69 balls there are 68 degrees of freedom. The NIST table of critical values puts the 5% cut-off for 68 degrees of freedom at 88.250 (NIST). A fair draw produces a score above that only 5% of the time, so a score above it would be a reason for a closer look. Our score of 74.9 is well under it. The spread in Part 1 is what equal chances look like. Our chi-square explainer walks through the test step by step.

Test 2: Do hot numbers stay hot?

Split the 1,440 draws into two halves of 720. Take the 10 balls drawn most often in the first half and see how they did in the second:

WITH numbered AS (
  SELECT draw_date,
         ROW_NUMBER() OVER (ORDER BY draw_date) AS draw_seq
  FROM powerball_draws
),
hits AS (
  SELECT n.draw_seq, w.ball
  FROM white_balls AS w
  JOIN numbered AS n ON n.draw_date = w.draw_date
),
counts AS (
  SELECT ball,
         SUM(draw_seq <= 720) AS first_720,
         SUM(draw_seq > 720) AS last_720
  FROM hits
  GROUP BY ball
),
top_ten AS (
  SELECT * FROM counts
  ORDER BY first_720 DESC, ball
  LIMIT 10
)
SELECT ROUND(AVG(first_720), 1) AS avg_first_720,
       ROUND(AVG(last_720), 1) AS avg_last_720,
       ROUND(720 * 5.0 / 69, 1) AS expected
FROM top_ten;

Result:

avg_first_720avg_last_720expected
64.554.452.2

The ten hottest balls were drawn well above the expected count in the first half, then fell back close to it in the second. This is regression to the mean: the balls that ran hot by luck stop running hot, because luck doesn't carry over from one draw to the next. Our post on the law of large numbers explains the pattern.

Test 3: Backtest a "hot numbers" system

A backtest plays a strategy against past draws using only information available before each draw. This one goes through every draw from the 101st onward, picks the five white balls drawn most often in the previous 100 draws, and counts how many of them appeared. The BETWEEN t.draw_seq - 100 AND t.draw_seq - 1 join is what keeps the future out of each pick.

WITH numbered AS (
  SELECT draw_date,
         ROW_NUMBER() OVER (ORDER BY draw_date) AS draw_seq
  FROM powerball_draws
),
hits AS (
  SELECT n.draw_seq, w.ball
  FROM white_balls AS w
  JOIN numbered AS n ON n.draw_date = w.draw_date
),
hot_counts AS (
  SELECT t.draw_seq AS target_seq, h.ball, COUNT(*) AS times_drawn
  FROM numbered AS t
  JOIN hits AS h
    ON h.draw_seq BETWEEN t.draw_seq - 100 AND t.draw_seq - 1
  WHERE t.draw_seq > 100
  GROUP BY t.draw_seq, h.ball
),
picks AS (
  SELECT target_seq, ball
  FROM (
    SELECT target_seq, ball,
           ROW_NUMBER() OVER (PARTITION BY target_seq
                              ORDER BY times_drawn DESC, ball) AS hot_rank
    FROM hot_counts
  )
  WHERE hot_rank <= 5
)
SELECT COUNT(DISTINCT p.target_seq) AS draws_tested,
       COUNT(h.ball) AS balls_matched,
       ROUND(COUNT(h.ball) * 1.0 / COUNT(DISTINCT p.target_seq), 3) AS matches_per_draw,
       ROUND(5 * 5.0 / 69, 3) AS expected_by_chance
FROM picks AS p
LEFT JOIN hits AS h
  ON h.draw_seq = p.target_seq AND h.ball = p.ball;

Result:

draws_testedballs_matchedmatches_per_drawexpected_by_chance
13404790.3570.362

If picks don't matter, five picks should match 5 × 5 ÷ 69 ≈ 0.362 white balls per draw on average. The hot-number system matched 0.357.

Test 4: Backtest an "overdue numbers" system

The opposite strategy picks the five balls that have gone longest without appearing, using the MAX(draw_seq) idea from Part 2:

WITH numbered AS (
  SELECT draw_date,
         ROW_NUMBER() OVER (ORDER BY draw_date) AS draw_seq
  FROM powerball_draws
),
hits AS (
  SELECT n.draw_seq, w.ball
  FROM white_balls AS w
  JOIN numbered AS n ON n.draw_date = w.draw_date
),
last_seen AS (
  SELECT t.draw_seq AS target_seq, h.ball, MAX(h.draw_seq) AS last_seq
  FROM numbered AS t
  JOIN hits AS h ON h.draw_seq < t.draw_seq
  WHERE t.draw_seq > 100
  GROUP BY t.draw_seq, h.ball
),
picks AS (
  SELECT target_seq, ball
  FROM (
    SELECT target_seq, ball,
           ROW_NUMBER() OVER (PARTITION BY target_seq
                              ORDER BY last_seq, ball) AS overdue_rank
    FROM last_seen
  )
  WHERE overdue_rank <= 5
)
SELECT COUNT(DISTINCT p.target_seq) AS draws_tested,
       COUNT(h.ball) AS balls_matched,
       ROUND(COUNT(h.ball) * 1.0 / COUNT(DISTINCT p.target_seq), 3) AS matches_per_draw,
       ROUND(5 * 5.0 / 69, 3) AS expected_by_chance
FROM picks AS p
LEFT JOIN hits AS h
  ON h.draw_seq = p.target_seq AND h.ball = p.ball;

Result:

draws_testedballs_matchedmatches_per_drawexpected_by_chance
13404940.3690.362

Test 5: Compare with picking the same numbers every time

For a baseline, here's the result of picking 1, 2, 3, 4 and 5 in every one of the same 1,340 draws:

WITH numbered AS (
  SELECT draw_date,
         ROW_NUMBER() OVER (ORDER BY draw_date) AS draw_seq
  FROM powerball_draws
),
hits AS (
  SELECT n.draw_seq, w.ball
  FROM white_balls AS w
  JOIN numbered AS n ON n.draw_date = w.draw_date
)
SELECT COUNT(*) AS balls_matched,
       ROUND(COUNT(*) * 1.0 / (SELECT COUNT(*) FROM numbered WHERE draw_seq > 100), 3) AS matches_per_draw
FROM hits
WHERE draw_seq > 100
  AND ball IN (1, 2, 3, 4, 5);

Result:

balls_matchedmatches_per_draw
4820.36

What the backtests show

Hot numbers matched 0.357 balls per draw, overdue numbers 0.369 and the fixed 1-2-3-4-5 pick 0.36. Chance predicts 0.362. Over 1,340 draws, chance alone moves this average by roughly ±0.03 either way (two standard errors; a single pick of five matches 0.36 balls on average with a standard deviation of about 0.56). All three results are inside that range, so none of the strategies did better than chance, including the one that ignores history completely.

That's the expected outcome. Powerball draws are independent: the machine and balls have no memory of earlier draws, so past frequency and past gaps carry no information about the next result. Our post on why each draw forgets covers it in more depth. The odds of a Powerball jackpot are 1 in 292,201,338 per play (Wikipedia) whichever numbers you choose.

So what is SQL good for?

If you play, play for fun, with money you can afford to lose. Our learn the math hub has more on odds and randomness, and help is available at 1-800-GAMBLER.

About the practice data

The sample files come from the DrawAnalytics results database, the same records behind our Powerball pages and state results pages. They're free to use; if you publish something made with them, please credit DrawAnalytics with a link.

Two things are worth knowing. The jackpot column is the jackpot advertised for each draw; for a draw where the jackpot was won, it's the amount the lottery announced, which can be a little higher than the estimate before the draw. And a few individual draws in our database have been wrong before, so for anything that matters, such as checking a ticket, use the lottery's official results. Powerball's are at powerball.com. Developers who want more data can use our free results API.

Sources

DrawAnalytics is an informational service. We do not sell predictions or guarantee outcomes. Lottery drawings are random — past results do not predict future drawings. Play responsibly. 1-800-GAMBLER.

Need to talk to someone about gambling?

Free, confidential help is available 24/7. Call or text 1-800-GAMBLER (1-800-426-2537) or visit ncpgambling.org.

DrawAnalytics is an informational and entertainment service. We provide historical lottery data analysis and pattern exploration tools. We do not sell predictions, we do not guarantee any outcome, and we make no representation that any tool on this site improves a user's probability of winning any lottery game. Lottery drawings are random. Past results do not predict future drawings. DrawAnalytics is independent and is not affiliated with or endorsed by any state lottery, the Multi-State Lottery Association, Powerball or Mega Millions. Game names are trademarks of their respective owners. Results are collected from public sources and may contain errors; official lottery results prevail. You must be 18 or older (21+ in some states) to play state lottery games. If you or someone you know has a gambling problem, call 1-800-GAMBLER or visit ncpgambling.org.