Mysql Group by counting issue -
database structure
table 'applicants'
id org_id team_id 1 1 1
table 'teams'
id name 1 test
table 'teams_members'
id team_id user_id 1 1 1 2 1 2
table 'users_playeraccounts'
id user_id summoner_id rank_solo 1 1 1 5 2 1 2 8 3 2 3 7 select sum(rank_solo) rank_sum, max(rank_solo) highest_rank, count(tt.id) members, t.name, o.team_id applicants o join teams t on o.team_id = t.id join teams_members tt on t.id = tt.team_id join users_playeraccounts p on tt.user_id = p.user_id org_id = :org group team_id
this offcourse gives me result like
rank_sum highest_rank members name team_id 20 8 3 test 1
is there way me both count of members playeraccounts aka
if 1 user has 2 it'll 2
and way me keep 1 literally counts rows found in teams_members neglecting entries in users_playeraccounts?
i want receive both 2 , 3 result of query.
you want count distinct number of entries in tt.id
, can this:
select ... count(distinct tt.id) distinct_members ...
rather giving count of every row has non-null tt.id
, you'll count of number of unique values.
Comments
Post a Comment