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

  • Home
  • SEARCH
  • 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 518583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:57:06+00:00 2026-05-13T07:57:06+00:00

I have a table in my database containing football results, the relevant columns being

  • 0

I have a table in my database containing football results, the relevant columns being matchNumber (a number based on the date), Result (either “W”, “D” or “L”) goalsFor, goalsAg and manager.

I have this query:

SELECT COUNT(*) AS P,  
(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W") AS W,  
(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "D") AS D,  
(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "L") AS L,  
SUM(GoalsFor) AS F,  
SUM(GoalsAg) AS A,  
ROUND((SELECT SUM((((SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W") * 2) +(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "D")))/((SELECT COUNT(*) FROM match_results WHERE manager = 13)*2)*100),2) AS pct  
FROM match_results WHERE manager = 13;

which returns the following result:

P   W  D  L  F   A   Pct  
213 92 49 72 296 247 54.69

This works perfectly. However, the results span a number of seasons and I want to break the output of the query down to reflect this. I have tried the following:

SELECT LEFT(matchNumber,4) AS Season,  
COUNT(*) AS P,  
(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W") AS W,  
(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "D") AS D,  
(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "L") AS L,  
SUM(GoalsFor) AS F,  
SUM(GoalsAg) AS A,  
ROUND((SELECT SUM((((SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W") * 2) +(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "D")))/((SELECT COUNT(*) FROM match_results WHERE manager = 13)*2)*100),2) AS pct  
FROM match_results WHERE manager = 13  
GROUP BY Season;

The outcome of this query can be seen in this image:

http://www.kidderminsterharriers.com/images/query2.jpg

As you can see, the ‘Season’, ‘P’, ‘F’ and ‘A’ columns have given me the result that I want but the remaining columns are repeating the totals. My question, therefore, is how can I adapt my query so that the ‘W’, ‘D’ and ‘L’ columns also give me year-by-year totals in each line of the output and not the total?

  • 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-13T07:57:07+00:00Added an answer on May 13, 2026 at 7:57 am

    The problem is your three subqueries do not limit their count by season. Try changing it to:

    SELECT @season:=LEFT(matchNumber,4) AS Season,  
    COUNT(*) AS P,  
    (SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W" AND LEFT(matchNumber,4)=@season) AS W,  
    (SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "D" AND LEFT(matchNumber,4)=@season) AS D,  
    (SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "L" AND LEFT(matchNumber,4)=@season) AS L,  
    SUM(GoalsFor) AS F,  
    SUM(GoalsAg) AS A,  
    ROUND((SELECT SUM((((SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W") * 2) +(SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "D")))/((SELECT COUNT(*) FROM match_results WHERE manager = 13)*2)*100),2) AS pct  
    FROM match_results WHERE manager = 13  
    GROUP BY Season;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').
I have a java class containing all the columns of a database table as
I have a table in a Oracle database containing a date field EXPIRYDATE. I
I have a database table containing the following columns: id code value datetime timestamp
I have a staff database table containing staff members, with user_no and user_name columns.
I have a database table containing the news on my site. It's divided into
I have a database containing a single huge table. At the moment a query
In my database I have table AnimalDetails containing animalNumber(primary key),name,breed dateofbirth and an image
Suppose I have an Oracle 11.2 database containing the following table: TABLE: SURVEY PARAMETER
i have database table like this +-------+--------------+----------+ | id | ip | date |

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.