Double grouping - separated group by n,m a comma group by n,m
I.e
select a, b, count(*) ct from table1 group by com_n,count
Well, we want a draw - here
select a,b, count(*) ct from table1 where a = b group by a,b
It remains a trifle - bring the table to score1 = a and score2 = b.
select a.count, b.count, count(*) ct from table2 a inner join table2 b on a.match_id = b.match_id and a.com_n <> b.com_n where a.count = b.count group by a.count, b.count
Under "normal" conditions (there are no duplicates, build-ups, and so on), the result will be good. You can add grouping by match - then it will be known what kind of idi matches won.
If the answer is one number ... stop ... And now the joke is grouping ... heaving in this case is not needed at all. I looked at the monster above, and decided to "cut down" the group ... so
select * from table2 a inner join table2 b on a.match_id = b.match_id and a.com_n <> b.com_n and a.count = b.count
Or one number - replacing * with count(*)
having max(count)=min(count)maximum number in the group can be equal to the minimum only if you have a draw - MikeHAVING ... AND COUNT(*) = 2(and in a good way, we must also check that there are two teams, and not one two times) ... For it’s considered “kosyachny” matches are absolutely not necessary - Akina