Skip to main content
2 of 2
wrong code
Rick James
  • 79.4k
  • 5
  • 51
  • 117
SELECT  LEAST(source, dest),
        GREATEST(source, dest),
        SUM(IF(source < dest, value, 0)),
        SUM(IF(source > dest, value, 0))
    FROM  tbl
    GROUP BY  1,2;
Rick James
  • 79.4k
  • 5
  • 51
  • 117