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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:24:30+00:00 2026-06-09T02:24:30+00:00

SELECT COUNT(m.winner = p.userName) AS wins, YEAR(m.datePlayed) AS year, DATE_FORMAT(m.datePlayed, ‘%M’) AS month, COUNT(*)

  • 0
SELECT COUNT(m.winner = p.userName) AS wins, YEAR(m.datePlayed) AS year, DATE_FORMAT(m.datePlayed, '%M') AS month, COUNT(*) as games FROM allMatches AS m LEFT JOIN playerUsers AS p ON m.season = p.season AND (m.player1 = p.userName OR m.player2 = p.userName) WHERE p.realName = '$realName' AND m.winner != '' AND m.canceled != '1' GROUP BY YEAR(m.datePlayed), MONTH(m.datePlayed)";

We have 2 tables we’re joining: allMatches and playerUsers. A PlayerUser has a username which matches to either player1 or player2 (and possibly to winner) on the allMatches table for a given season.

I want to count the number of games played (any match they’re in) and the number of games they’ve won (where their username on playerUsers matches winner on allMatches). The above SQL statement returns both wins and games as the same number. Is there a way to count the number of wins and games in the same SQL statement?

  • 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-06-09T02:24:32+00:00Added an answer on June 9, 2026 at 2:24 am

    Use SUM instead of COUNT to calculate the number of wins:

    SELECT SUM(m.winner = p.userName) AS wins, ...
    

    It works because the boolean expression evaluates to either 0 and 1, and so SUM gives you the total number of rows where the expression was true.

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

Sidebar

Related Questions

SQL : SELECT COUNT(usr.id) as `total_results` FROM users as usr LEFT JOIN profile as
i have this SELECT COUNT(1) cnt, a.auther_id FROM `posts` a LEFT JOIN users u
select count (*) from sales_order where date_format (created_at,'%Y-%m-%d') >= '2009-11-02' and date_format(created_at,'%Y-%m-%d') <= '2010-12-08'
SELECT COUNT( np.id ) FROM new_people np LEFT JOIN institute.users_roles ur ON np.institute_uid =
SELECT COUNT(*) AS count, state, DATE_FORMAT( '%m/%d', registered ) AS date_formatted FROM users WHERE
I have this statement: SELECT COUNT(AccedentId) AS NumberOfAccedentInYear FROM Accident GROUP BY DriverId, YEAR(AccedentDate)
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
SELECT COUNT(`t`.id) FROM `product` `t` INNER JOIN `category` `c1` ON ( `c1`.id ='15' )
SELECT * FROM( (SELECT count(DISTINCT RECEPIENT_ID) as NoOfUsers, TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD') as accDate FROM ALRT_PLATFORM_ALRT_HSTRY where
TOPIC_COUNT_SQL = SELECT COUNT(*) FROM topics_topic WHERE topics_topic.object_id = maps_map.id AND topics_topic.content_type_id = %s

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.