Skip to content
Advertisement

SQL statement HOW to count all relevant rows (A,B) and (B,A) together

I am trying to count all rows where seller and buyer has also an inverted relationship. So the buyer sells to seller. I do not have any clue to group them together.

Now I would like count the relations between seller and counter.

right now, i am able to count the relation seller to buyer without combining the inverted way with

But i wold like to have row 1 and 2 together with the count of 3

Any help, advice…

Advertisement

Answer

You can use least() and greatest() if your database supports them (SQL Server is a notable exception):

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement