Skip to main content
wrong code
Source Link
Rick James
  • 79.4k
  • 5
  • 51
  • 117
SELECT  LEAST(source, dest),
        GREATEST(source, dest),
        SUM(IF(source < dest, sourcevalue, 0)),
        SUM(IF(source <> dest, destvalue, 0))
    FROM  tbl
    GROUP BY  1,2;
SELECT  LEAST(source, dest),
        GREATEST(source, dest),
        SUM(IF(source < dest, source, 0)),
        SUM(IF(source < dest, dest, 0))
    FROM  tbl
    GROUP BY  1,2;
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;
Source Link
Rick James
  • 79.4k
  • 5
  • 51
  • 117

SELECT  LEAST(source, dest),
        GREATEST(source, dest),
        SUM(IF(source < dest, source, 0)),
        SUM(IF(source < dest, dest, 0))
    FROM  tbl
    GROUP BY  1,2;