/    Sign up×
Community /Pin to ProfileBookmark

GROUP BY COUNTS Over two columns

I have the following table format.

ID, Player1ID, Player2ID, RingID

What I want to do is display all players and a count for how many times they’ve played in a particular ring.

On any given row the player could be player1 or player2.

I know I can filter the RingID in the where clause.

“`
SELECT DISTINCT p.playerId, COUNT(`fightId`) as Fight

FROM `fights` f
JOIN `players` p ON f.player1ID OR f.player2ID = p.playerId

WHERE `venueId` = 2

GROUP BY p.playerId
“`

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@VITSUSAJan 20.2021 — Can you please share any reference links to understand the exact requirement?
Copy linkTweet thisAlerts:
@NogDogJan 20.2021 — Guessing you already took care of this by now, but just in case, the join syntax would be:
<i>
</i>JOIN <span><code>players</code></span> p ON f.player1ID = p.playerId OR f.player2ID = p.playerId
^
|
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...