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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:09:52+00:00 2026-05-23T21:09:52+00:00

Some friends and I are writing a php site where we can log our

  • 0

Some friends and I are writing a php site where we can log our matches, create tournaments and log matches for these tournaments etc.

We hit a wall with displaying our matches for a certain tournament. We tried doing it with php but that messes up the tournament table totally

We have a table called matches where we have following columns:

ID  player1ID player2Id  team1ID team2ID ScorePlayer1 ScorePlayer2  Date TournamentID

Now we want to make tables like:

GPl        W    L    D    +    -    +/-       Pnts
Nielsen    6    1    3    2    3    6    -3    13
Chibax     6    2    1    3    4    3     1    9
Verre      6    1    3    2    3    6    -3    5
Hermie     6    4    1    1    7    2     5    5

But with php the rows with W L D and points never match , the whole table is weird.

Anyone have an idea of how we can do this with an SQL command ? (for non-soccer people: wins x 3 pnts Draws x 1 pnts losses 0 pnts

  • 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-23T21:09:53+00:00Added an answer on May 23, 2026 at 9:09 pm

    I don’t know if mysql with php still shuns subqueries but the following might have a chance of working. I’ll test it later on as I don’t have the time at the moment. I just though I’d give you some ideas.

    If the subqueries do not work then you could create a view of the subquery and proceed from there.

    I’m also not sure if mysql supports column names that are expressed using double quotes ("+/-")

    The basic idea is to select the score separately for home games and visiting games. Aggregate functions allow usually allow case statements within them that allows you to do a bit magic.

    SELECT 
      player, 
      SUM(M) M, 
      SUM(W) W,
      SUM(E) E,
      SUM(D) D,
      SUM("+") "+",
      SUM("-") "-",
      SUM("+/-") "+/-",
      SUM(Pnts) Pnts
    FROM (
      SELECT  
        player1ID player,
        count(*) M,
        SUM(case when ScorePlayer1 > ScorePlayer2 then 1 end) W,
        SUM(case when ScorePLayer1 < ScorePlayer2 then 1 end) E,
        SUM(case when ScorePlayer1 = ScorePlayer2 then 1 end) D
        SUM(ScorePlayer1) "+",
        SUM(ScorePlayer2) "-",
        SUM(ScorePlayer1) - SUM(ScorePlayer2) "+/-",
        SUM(case when ScorePlayer1 > ScorePlayer2 then 1 end) * 3 +
        SUM(case when ScorePLayer1 < ScorePlayer2 then 1 end) Pnts
      FROM 
        someTable
      GROUP BY
        player1ID
      UNION ALL
      SELECT  
        player2ID player,
        count(*) M,
        SUM(case when ScorePlayer2 > ScorePlayer1 then 1 end) W,
        SUM(case when ScorePLayer2 < ScorePlayer1 then 1 end) E,
        SUM(case when ScorePlayer2 = ScorePlayer1 then 1 end) D
        SUM(ScorePlayer2) "+",
        SUM(ScorePlayer1) "-",
        SUM(ScorePlayer2) - SUM(ScorePlayer1) "+/-",
        SUM(case when ScorePlayer2 > ScorePlayer1 then 1 end) * 3 +
        SUM(case when ScorePLayer2 < ScorePlayer1 then 1 end) Pnts
      FROM 
        someTable
      GROUP BY
        player2Id
     ) scoresheet
     ORDER BY
        Pnts desc,
        M asc,
        "+/-" desc,
        "+" desc,
        "-" asc
    

    Edit: I forgot to order the results. You need a bit magic if you want to use matches between players A and B to order the results in case of a tie.

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

Sidebar

Related Questions

I am writing some Java questions to help my friends in the Java exam.
Me and some friends are writing a MORPG in Java, and we would like
Im writing a Twitter Client in C#/WPF/WCF. I(Windows) showed some of my friends(OS X)
I'm writing up a small series of tutorials for some friends of mine introducing
I'm currently writing a simple application for some friends of mine. There is a
I'm writing a Facebook application that accesses the user's friends' photos. For some reason,
I am just curious, I am writing some notes for a friend and am
Some friends and I wanted to develop a game. Any language will do. I've
I'm working on a C project with some friends for school. They helped me
I am developing a simple library in C, for my own + some friends

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.