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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:54:26+00:00 2026-05-21T22:54:26+00:00

I’ve already got this to work but it’s a really bad approach and i

  • 0

I’ve already got this to work but it’s a really bad approach and i need some help with factorization of my query.

SELECT `GameDate`,
   COUNT(CASE
           WHEN `P1Outcome`= 'win' AND  P2Param = 'a' THEN 1 
         END) AS a_win,
   COUNT(CASE
           WHEN `P1Outcome`= 'loss' AND  P2Param = 'a' THEN 1 
         END) AS a_loss,
   COUNT(CASE
           WHEN `P1Outcome`= 'win' AND  P2Param = 'b' THEN 1
         END) AS b_win,
   COUNT(CASE
           WHEN `P1Outcome`= 'loss' AND  P2Param = 'b' THEN 1
         END) AS b_loss
    FROM games 
    WHERE `P2Param` IN ( 'a', 'b', 'c' ) 
    GROUP BY GameDate

This will get me an query that i can use in my php application but i would like to skip having to make the actual ratio calculation in php and fetch it directly with SQL.

So basically what i’ve been trying to do is something similar to this:

   COUNT(CASE
           WHEN `P1Outcome`= 'win' AND  P2Param = 'a' THEN 1 Else -1
         END) AS a_ratio,

But just as the beginer i’m, i can’t figure it out how i can make this to work.

EDIT:
Sorry for not explaining my regards in more details, here is the thing. I’m creating an statistics component and i need to fetch the ratio for a period of time in order to display it as an graph. So the following things are required:

GameDate (1,2,3,4… days ago)
The ratio for the player based on to different params (maps in this case)

So in short this is what i got at the moment:

GameDate      a_win      a_loss    b_win      b_loss 
2011/04/25     x          x         x           x
2011/04/23     x          x         x           x
....

So everything works out great, but i would like to have the actual ratio calculation made in SQL because at the moment i need to make it in php e.g $ratio = $q[a_win]-$q[a_loss] and due to the fact that I’ve a lot of different param my query is like double the size because i need to fetch both the win and loss instead of just the ratio like i want in the first place.

  • 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-21T22:54:26+00:00Added an answer on May 21, 2026 at 10:54 pm
    SELECT `GameDate`,
       SUM(CASE `P2Param`
             WHEN 'a' THEN CASE P1Outcome WHEN 'win' THEN 1 ELSE -1 END
             ELSE 0
           END) AS a_ratio,
       SUM(CASE `P2Param`
             WHEN 'b' THEN CASE P1Outcome WHEN 'win' THEN 1 ELSE -1 END
             ELSE 0
           END) AS b_ratio
    FROM games
    WHERE `P2Param` IN ( 'a', 'b', 'c' ) 
    GROUP BY GameDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.