Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:18:43+00:00 2026-06-07T23:18:43+00:00

All, I have a table that looks like this: Date Pitcher WHIP ——– ————–

  • 0

All,

I have a table that looks like this:

Date     Pitcher        WHIP
-------- -------------- -----
7/4/12   JACKSON, E     1.129
7/4/12   YOUNG, C       1.400
7/4/12   CORREIA, K     1.301
7/4/12   WOLF, R        1.594
...
6/28/12  JACKSON, E     1.137
6/27/12  YOUNG, C       1.750
...
6/19/12  JACKSON, E     1.215
6/17/12  YOUNG, C       1.851

I’ve set up a SQLFiddle here: http://sqlfiddle.com/#!2/addfe/1

In other words, the table lists the starting pitcher for every game of the MLB season, along with that pitcher’s current WHIP (WHIP is a measure of the pitcher’s performance).

What I’d like to obtain from my query is this: how much has that pitcher’s WHIP changed in the last 30 days?

Or, more precisely, how much has that pitcher’s WHIP changed since his most recent start that was at least 30 days ago?

So, for example, if E. Jackson’s WHIP on 7/4/12 was 1.129, and his WHIP on 6/3/12 was 1.500, then I’d like to know that his WHIP changed by -0.371.

This is easy to figure out for any individual, but I want to calculate that for all pitchers, on all dates.

One of the things that makes this tricky is that there isn’t data for every date. For example, if E. Jackson pitched on 7/4/12, the most recent start that’s at least 30 days ago might be on 5/28/2012.

However, for K. Correia, who also pitched on 7/4/12 – his most recent start that’s at least 30 days ago might be 5/26/2012.

I’m assuming that I need to join the table to itself, but I’m not sure how to do it.

Here’s my first stab:

select
    t1.home_pitcher,
    t1.date,
    t1.All_starts_whip,
    t2.All_starts_whip
from
    mlb_data t1
join
    mlb_data t2
ON
    t1.home_pitcher = t2.home_pitcher
and
    t2.date = (select max(date) from mlb_data t3 where t3.home_pitcher = t1.home_pitcher and t3.date < date_sub(t1.date, interval 1 month))

This seems to work (and hopefully illustrates what I’m trying to capture), but takes HORRENDOUSLY long – my table goes back a few seasons, and has about 6,250 rows – and this query took 7,289 seconds (yes, that’s correct – more than 2 hours). I’m sure this is a classic case of the absolute worst way to right a query.

[UPDATE] Some clarification…

The query should produce a value for EACH pitcher for EACH start.

In other words, if E. Jackson pitched in 10 games, he’d be listed in the result set 10 times.

Date     Pitcher        WHIP  WHIP_30d_ago
-------- -------------- ----- ------------
7/4/12   JACKSON, E     1.129 1.111
...
5/18/12  JACKSON, E     1.111 2.222
...
4/14/12  JACKSON, E     2.222 3.333

In other words, I’m looking for a 30-day trailing WHIP for each start.

Many thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:18:46+00:00Added an answer on June 7, 2026 at 11:18 pm

    I don’t think you need a self join for that.. you can use a sub-query like this:

    select
            t1.home_pitcher,
            t1.date,
            t1.All_starts_whip,
           (SELECT t2.all_starts_whip FROM mlb_data t2 
            WHERE 
            t2.date < date_sub(t1.date, interval 1 month) 
            AND t2.home_pitcher=t1.home_pitcher 
            ORDER   BY t2.date DESC LIMIT 1) as previous_whip,
            t1.all_starts_whip - previous_whip 
    
        FROM 
            mlb_data t1
    

    So for each whip score for each player, you get the previous month s latest score and calculate the evolution.

    Check it out: http://sqlfiddle.com/#!2/addfe/8 (Some entries don t have a previous month entry to calculate the difference so it’s null)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table code_prices that looks something like this: CODE | DATE |
I have a table that looks like this, Date Value 01/01/2010 03:59:00 324.44 01/02/2010
I have a table that essentially looks like this: CREATE TABLE myTable ( id
I have a table that looks like this: I have this same chart on
I have a table that looks like this: ------------------------------------------------------------------- CUSTNUM (INT), ITEMNUM (INT), MONTH
I have a table that looks like this CREATE TABLE `purchases` ( `id` INT(10)
I have this table that looks like this CREATE TABLE `purchases` ( `id` INT(10)
I have data in my database that looks like this: Date (DateTime) Type (varchar)
I have a table with a row that looks like this: ( 20091231 48498429,
I have a user table that has many columns, it looks roughly like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.