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 8680997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:23:28+00:00 2026-06-12T21:23:28+00:00

THIS IS USING MYSQL My question is the following. I have a baseball database,

  • 0

THIS IS USING MYSQL
My question is the following. I have a baseball database, and in that baseball database there is a master table which lists every player that has ever played. There is also a batting table, which tracks every players’ batting statistics. I created a view to join those two together; hence the masterplusbatting table.
I now want to find the highest HR hitter in each decade since baseball began. Here is what I tried.

    select f.yearID, truncate(f.yearid/10,0) as decade,f.nameFirst, f.nameLast, f.HR
    from (
    select yearID, max(HR) as HOMERS
    from masterplusbatting group by yearID
    )as x inner join masterplusbatting as f on f.yearID = x.yearId and f.HR = x.HOMERS
    group by decade

You can see that I truncated the yearID in order to get 187, 188, 189 etc instead of 1897, 1885,. I then grouped by the decade, thinking that it would give me the highest per decade, but it is not returning the correct values. For example, it’s giving me Adrian Beltre with 48 HR’s in 2004 but everyone knows that Barry Bonds hit 73 HR in 2001. Can anyone give me some pointers?

  • 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-12T21:23:30+00:00Added an answer on June 12, 2026 at 9:23 pm
    SELECT
      Lookup.DecadeID,
      Data.*
    FROM
    (
      SELECT
        truncate(yearid/10,0) as decadeID,
        MAX(HR) as Homers
      FROM
        masterplusbatting
      GROUP BY
        truncate(yearid/10,0)
    )
      AS lookup
    INNER JOIN
      masterplusbatting AS data
        ON  data.yearid >= lookup.decadeID * 10
        AND data.yearid <  lookup.decadeID * 10 + 10
        AND data.HR     =  lookup.homers
    

    Editted for MySQL

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

Sidebar

Related Questions

I'm using MySQL. This is table i have Level Programmingtime Clientname projectid 0 128
I have a question about the following code which I'm using in a prepare-execute
Based on this question How to insert array into mysql using PDO and bindParam?
This is a winform and I'm using mysql as a database, here is my
I'm using MySQL with PHP. This is like my table: (I'm using 3 values,
I am using MySQL. I have several lookups like this: SELECT * from users
My table looks like this (and I'm using MySQL): m_id | v_id | timestamp
Please read Update1 first! This is SSIS specific question. I have the following tasks:
I have table with field called description which contains text like following |Description |
This is a follow up from my question: MySQL: Querying a table and possibly

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.