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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:12:31+00:00 2026-05-21T20:12:31+00:00

I have a series of button tag. SELECT team, COUNT( team ) AS pld,

  • 0

I have a series of button tag.

SELECT team, COUNT( team ) AS pld,  
  SUM( IF( Pts = 3, 1, 0 ) ) AS W,  
  SUM( IF( Pts = 1, 1, 0 ) ) AS D,  
  SUM( IF( Pts = 0, 1, 0 ) ) AS L,  
  SUM( Pts ) AS Pts,  
  SUM( GF ) AS GF,  
  SUM( GA ) AS GA,  
  SUM( GF ) - SUM( GA ) AS GD  
FROM (  
    SELECT home_team_id AS team,  
      home_goal_number AS GF,  
      away_goal_number AS GA,  
      CASE  
        WHEN home_goal_number > away_goal_number  
          THEN 3  
        WHEN home_goal_number = away_goal_number  
          THEN 1  
      ELSE 0  
      END AS Pts  
    FROM matches  
  UNION ALL 
    SELECT away_team_id AS team,  
      away_goal_number AS GF,  
      home_goal_number AS GA,   
      CASE  
        WHEN away_goal_number > home_goal_number  
          THEN 3  
        WHEN away_goal_number = home_goal_number  
          THEN 1  
        ELSE 0  
        END AS Pts  
      FROM matches  
) AS tab  
GROUP BY team  
ORDER BY Pts DESC

This work perfectly. There’s only one problem. If two teams end the league with the same points, the first way to remove the ambiguity is understand who win the direct match.

How can I modify this query to do that?

  • 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-21T20:12:32+00:00Added an answer on May 21, 2026 at 8:12 pm

    If you consider the only way to know there is a draw is to calculate the points using the query you have shown, you can see it is not an easy task to add the direct match winner information to the current query.

    I would consider putting the query you have in a VIEW and then creating a new query to use the view and calculate the overall winner where the number of points for two teams are equal.

    As I said in my comment, what do you do when the direct match is a draw or when more than two teams have the same number of points at the end of the competition? These cases are possible but difficult to code a solution for.

    An alternative is to use goal difference but that may require your league to change their rules 🙂

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

Sidebar

Related Questions

I have a series of divs that slide down using -webkit-transform from a negative
quick question... I have a series of buttons, each with a tag. I click
I have button series.ex.10 buttons.According to screen size it should be wrapped to 2
I have a series of iframes in my html page. Upon a button click,
I have randomly generated radio button series like <input type=radio name=creatorusers value=1> <input type=radio
I have a series of buttons and foreach button I have a seperate .click(function()
I have a series of editable lists which, on a press of a button
I have a button which when pressed makes calls that load information from a
I have a series of tabs that are displaying content from a remote source.
I have a series of radio buttons that I wish to show a count

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.