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;