SQL for Lottery Analysis series
- Part 1: Count how often each number is drawn
- Part 2: Find "overdue" numbers with window functions
- Part 3: Measure jackpot rollover streaks
- Part 4: Same number, same day, different states (you are here)
- Part 5: Test it all: why none of it predicts a draw
Free practice data: SQLite database · Powerball CSV · Pick 3/Pick 4 CSV
Here's a question that comes up whenever two states draw the same Pick 3 number on the same day: how unusual is that? This part answers it with a year of real results, using the pick_draws table in the sample database (or the Pick 3/Pick 4 CSV). Along the way it covers HAVING, GROUP_CONCAT and joining a table to itself.
Step 1: Look at the table
Each row is one draw of a Pick 3 or Pick 4 style game in 2025. The number column holds the digits as text, so 073 keeps its leading zero, and digits is 3 or 4.
SELECT digits,
COUNT(*) AS draws,
COUNT(DISTINCT state) AS states,
COUNT(DISTINCT draw_date) AS days
FROM pick_draws
GROUP BY digits;Result:
| digits | draws | states | days |
|---|---|---|---|
| 3 | 25781 | 37 | 365 |
| 4 | 25175 | 34 | 365 |
That's 25,781 three-digit draws and 25,175 four-digit draws. Many games draw more than once a day. In the table, Texas has four draws a day, six days a week. Here's one day in four big states:
SELECT state, game, draw_time, number
FROM pick_draws
WHERE digits = 3
AND draw_date = '2025-07-04'
AND state IN ('FL', 'NY', 'OH', 'TX')
ORDER BY state, draw_time;Result:
| state | game | draw_time | number |
|---|---|---|---|
| FL | Pick 3 | evening | 260 |
| FL | Pick 3 | midday | 620 |
| NY | Numbers | evening | 965 |
| NY | Numbers | midday | 569 |
| OH | Pick 3 | evening | 635 |
| OH | Pick 3 | midday | 998 |
| TX | Pick 3 | day | 774 |
| TX | Pick 3 | evening | 207 |
| TX | Pick 3 | morning | 857 |
| TX | Pick 3 | night | 431 |
Maine, New Hampshire and Vermont sell Pick 3 and Pick 4 through their joint Tri-State Lottery (Wikipedia), and in our records the three states' results are identical. The table keeps each of those drawings once, under ME/NH/VT. Otherwise every shared drawing would look like three states matching.
Step 2: Find numbers drawn in two or more states on one day
Group by date and number, then count the different states in each group. WHERE can't filter on a count, because the count doesn't exist until the rows are grouped. HAVING is the filter that runs after grouping. GROUP_CONCAT joins the matching states into one text value.
SELECT draw_date,
number,
COUNT(DISTINCT state) AS states,
GROUP_CONCAT(DISTINCT state) AS which_states
FROM pick_draws
WHERE digits = 3
GROUP BY draw_date, number
HAVING COUNT(DISTINCT state) >= 2
ORDER BY states DESC, draw_date
LIMIT 10;Result:
| draw_date | number | states | which_states |
|---|---|---|---|
| 2025-01-03 | 528 | 3 | DE,OK,VA |
| 2025-01-09 | 253 | 3 | DC,MD,NC |
| 2025-01-19 | 093 | 3 | MI,VA,WI |
| 2025-01-21 | 277 | 3 | DC,DE,GA |
| 2025-02-15 | 685 | 3 | NM,SC,TN |
| 2025-03-04 | 185 | 3 | CO,IL,MS |
| 2025-03-10 | 753 | 3 | CT,TN,WI |
| 2025-04-04 | 838 | 3 | CO,CT,LA |
| 2025-04-08 | 601 | 3 | IA,MI,NE |
| 2025-04-08 | 664 | 3 | FL,NC,WV |
On January 9, 2025, for example, 253 was drawn in the District of Columbia, Maryland and North Carolina. A match counts if it happened at any time that day, so one state's midday draw can match another's evening draw.
Step 3: How often does it happen?
WITH by_number AS (
SELECT draw_date, number, COUNT(DISTINCT state) AS states
FROM pick_draws
WHERE digits = 3
GROUP BY draw_date, number
)
SELECT states AS states_drawing_it, COUNT(*) AS date_number_combos
FROM by_number
GROUP BY states
ORDER BY states;Result:
| states_drawing_it | date_number_combos |
|---|---|
| 1 | 23957 |
| 2 | 870 |
| 3 | 25 |
WITH shared AS (
SELECT draw_date
FROM pick_draws
WHERE digits = 3
GROUP BY draw_date, number
HAVING COUNT(DISTINCT state) >= 2
)
SELECT COUNT(DISTINCT draw_date) AS days_with_a_match,
(SELECT COUNT(DISTINCT draw_date) FROM pick_draws WHERE digits = 3) AS days
FROM shared;Result:
| days_with_a_match | days |
|---|---|
| 338 | 365 |
In 2025 a three-digit number came up in two states on the same day 870 times, and in three states 25 times. No number came up in four states on one day. At least one match happened on 338 of the 365 days.
Step 4: Is that more than chance?
It sounds like a lot, until you count the chances. With about 71 Pick 3 draws a day across the country, there are thousands of ways to pair up two draws from different states each day. Any one pair matches with a chance of 1 in 1,000, since there are 1,000 possible three-digit numbers. This is the same idea as the birthday problem (Wikipedia): in a group of just 23 people, two probably share a birthday, because there are so many pairs.
SQL can count the pairs. The per_day step counts each state's draws per day, and multiplying two states' counts gives the number of draw pairs between them. The matches step joins pick_draws to itself, a self join: every draw is compared with every draw from another state on the same date, and b.state > a.state makes sure each pair is counted once.
WITH per_day AS (
SELECT draw_date, state, COUNT(*) AS draws
FROM pick_draws
WHERE digits = 3
GROUP BY draw_date, state
),
pairs AS (
SELECT SUM(a.draws * b.draws) AS draw_pairs
FROM per_day AS a
JOIN per_day AS b
ON b.draw_date = a.draw_date
AND b.state > a.state
),
matches AS (
SELECT COUNT(*) AS matching_pairs
FROM pick_draws AS a
JOIN pick_draws AS b
ON b.draw_date = a.draw_date
AND b.digits = a.digits
AND b.state > a.state
AND b.number = a.number
WHERE a.digits = 3
)
SELECT draw_pairs,
ROUND(draw_pairs / 1000.0, 1) AS expected_matches,
matching_pairs AS actual_matches
FROM pairs, matches;Result:
| draw_pairs | expected_matches | actual_matches |
|---|---|---|
| 885081 | 885.1 | 945 |
Chance predicts 885.1 matching pairs across the year, and the data has 945. (A number drawn in three states counts as three pairs, which is why this figure is higher than the Step 3 count.) Treating each pair as an independent 1 in 1,000 chance, random variation of about ±60 either way (two standard deviations) is normal, and 945 sits right at that edge. A result this far above chance or further turns up by luck about once in 42 years of draws like these, so it's unusual but not remarkable. Looking closer doesn't point to a link between states: the matches are spread across hundreds of state pairs and dates rather than piling up between a few states. Pick 4 has 10,000 possible numbers, so matches should be 10 times rarer:
WITH per_day AS (
SELECT draw_date, state, COUNT(*) AS draws
FROM pick_draws
WHERE digits = 4
GROUP BY draw_date, state
),
pairs AS (
SELECT SUM(a.draws * b.draws) AS draw_pairs
FROM per_day AS a
JOIN per_day AS b
ON b.draw_date = a.draw_date
AND b.state > a.state
),
matches AS (
SELECT COUNT(*) AS matching_pairs
FROM pick_draws AS a
JOIN pick_draws AS b
ON b.draw_date = a.draw_date
AND b.digits = a.digits
AND b.state > a.state
AND b.number = a.number
WHERE a.digits = 4
)
SELECT draw_pairs,
ROUND(draw_pairs / 10000.0, 1) AS expected_matches,
matching_pairs AS actual_matches
FROM pairs, matches;Result:
| draw_pairs | expected_matches | actual_matches |
|---|---|---|
| 841253 | 84.1 | 78 |
Chance predicts 84.1 and the data has 78, a little under chance and well within ordinary variation. The same number in several states on one day is a coincidence that happens nearly every day, at about the rate the odds say it should. It doesn't connect the drawings, and it doesn't make the number more or less likely next time.
Known gaps in this table
The table holds every 2025 draw in our database. Not every slot has 365 draws: several games, Texas among them, skip Sunday draws, and Nebraska Pick 4 starts on September 21, 2025, the day the game launched (Lottery.net). A few individual draws are missing too. The expected counts in Step 4 are built from the draws actually in the table, so the comparison is still fair. Checking counts per group like this before trusting a total is a good habit with any real data.
Try it yourself
- Find "box" matches, where two states drew the same digits in any order. Hint: build a sorted version of the number with
MIN,MAXand the middle digit, the way our database does, then group on that. - Count how often a state drew the same number twice on one day (midday and evening). Group by
state, draw_date, numberand keep groups withCOUNT(*) >= 2. - Check the table for gaps yourself:
SELECT state, digits, draw_time, COUNT(*) FROM pick_draws GROUP BY state, digits, draw_time; - See which numbers each state draws most often on our most common Pick 3 and Pick 4 numbers by state page.
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.
- powerball_draws: all 1,440 Powerball draws from October 7, 2015, the first drawing under today's 5-of-69 plus 1-of-26 format, to November 30, 2026. One row per draw: the five white balls (
n1ton5, smallest first), the redpowerball, the Power Play multiplier and the advertisedjackpotfor that draw. - pick_draws: the 50,956 Pick 3 and Pick 4 style draws from 2025 in our database, across every state game we track, one row per draw, with the number kept as text so a leading zero stays (
'073').
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.
Next: Part 5: Test it all: why none of it predicts a draw
Sources
- Birthday problem, Wikipedia
- Tri-State Lottery, Wikipedia
- Nebraska Pick 4 To Launch on September 21, Lottery.net
- Built-in Aggregate Functions, SQLite documentation
- The WITH Clause, SQLite documentation
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.