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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:48:04+00:00 2026-05-25T17:48:04+00:00

How would I get a query that joins these four tables, and also gives

  • 0

How would I get a query that joins these four tables, and also gives me the average?

Table1:
TeamId |   TeamName
  1    |      TA
  2    |      TB
  3    |      TC

Table2:
YearsId  | Years
    1    | 2009-2010
    2    | 2010-2011
    3    | 2011-2012

Table3:
MonthsId | Month
    1    |  July
    2    |  Aug
    3    |  Sept

Table4:
TeamId  | MonthsId  | YearsId  | TeamWinCount
    1   |     1     |    2     |        44
    1   |     1     |    3     |        11
    1   |     2     |    2     |        0
    1   |     12    |    3     |        13
    2   |     1     |    2     |        33

I would like to get results that look like this:

   Year    |  Team   | Avg (avg win count jun+aug+sept+.../12)
 2009-2010 |   TA    |   23.3
 2009-2010 |   TB    |   18.23    
 2009-2010 |   TC    |   35.23    
 2010-2011 |   TA    |   18.23    
 2010-2011 |   TB    |   18.23    
 2010-2011 |   TC    |   18.23    

If there is no entry for a month, it should be counted as 0

There must be some genius out there’s that’s done this before. I’ve played around with joining the tables, but can’t seem to get a column that is the average. Any help or direction is much appreciated!

  • 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-05-25T17:48:04+00:00Added an answer on May 25, 2026 at 5:48 pm

    Table3 is not needed here

    SELECT Table2.Years,Table1.TeamName,IFNULL(AVG(TeamWinCount), 0) AS TeamWinCount
    FROM Table2
    CROSS JOIN Table1
    LEFT JOIN Table4 ON Table1.TeamId=Table4.TeamId AND Table2.YearsId=Table4.YearsId
    GROUP BY Table2.Years,Table1.TeamName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex query that joins different tables to get the count. There
Is there a way to get the columns that a SQL query would return
I have a query that joins two tables. One table has a column that
I have the following SQL query that performs a subquery and joins two tables
How would you write a SQL query to get the size of blob in
I would like to get the final SQL query, with parameter values bound (replaced)
Using a FindByAttributes query I would like to get the oldest element out of
I have one query on which I would like to get your valuable feedback.
How would get find an average from an array? If I have the array:
I'm looking for a method or an event that would get fired when a

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.