2 added 4 characters in body
source | link

You need to sort origin and destination first, to make the pairs with the same end points equal. You asAs it's only two columns, you can do that in a CASE ... END here. Then you can GROUP BY these and get the count(*).

 SELECT CASE 
          WHEN origin <= destination
            THEN origin
          ELSE
            destination
        END,
        CASE 
          WHEN destination >= origin
            THEN destination
          ELSE
            origin
        END,
        count(*)
        FROM routes
        GROUP BY CASE 
                   WHEN origin <= destination
                     THEN origin
                   ELSE
                     destination
                 END,
                 CASE 
                   WHEN destination >= origin
                     THEN destination
                   ELSE
                     origin
                 END;

You need to sort origin and destination first, to make the pairs with the same end points equal. You as it's only two, you can do that in a CASE ... END here. Then you can GROUP BY these and get the count(*).

 SELECT CASE 
          WHEN origin <= destination
            THEN origin
          ELSE
            destination
        END,
        CASE 
          WHEN destination >= origin
            THEN destination
          ELSE
            origin
        END,
        count(*)
        FROM routes
        GROUP BY CASE 
                   WHEN origin <= destination
                     THEN origin
                   ELSE
                     destination
                 END,
                 CASE 
                   WHEN destination >= origin
                     THEN destination
                   ELSE
                     origin
                 END;

You need to sort origin and destination first, to make the pairs with the same end points equal. As it's only two columns, you can do that in a CASE ... END here. Then you can GROUP BY these and get the count(*).

 SELECT CASE 
          WHEN origin <= destination
            THEN origin
          ELSE
            destination
        END,
        CASE 
          WHEN destination >= origin
            THEN destination
          ELSE
            origin
        END,
        count(*)
        FROM routes
        GROUP BY CASE 
                   WHEN origin <= destination
                     THEN origin
                   ELSE
                     destination
                 END,
                 CASE 
                   WHEN destination >= origin
                     THEN destination
                   ELSE
                     origin
                 END;
1
source | link

You need to sort origin and destination first, to make the pairs with the same end points equal. You as it's only two, you can do that in a CASE ... END here. Then you can GROUP BY these and get the count(*).

 SELECT CASE 
          WHEN origin <= destination
            THEN origin
          ELSE
            destination
        END,
        CASE 
          WHEN destination >= origin
            THEN destination
          ELSE
            origin
        END,
        count(*)
        FROM routes
        GROUP BY CASE 
                   WHEN origin <= destination
                     THEN origin
                   ELSE
                     destination
                 END,
                 CASE 
                   WHEN destination >= origin
                     THEN destination
                   ELSE
                     origin
                 END;