If you're wanting to update a table in this manner you can use a Stored Procedure:
CREATE TABLE T (ID VARCHAR(5), N1 INT);
DELIMITER $$
CREATE PROCEDURE check_vals (IN a VARCHAR(5), IN b VARCHAR(5)) BEGIN
SET @a = (SELECT N1 FROM T WHERE ID = a);
SET @b = (SELECT N1 FROM T WHERE ID = b);
IF @a > @b THEN UPDATE T SET N1 = @b WHERE ID = a;
ELSE UPDATE T SET N1 = @a WHERE ID = b;
END IF;
END $$
DELIMITER ;
Then Just use the procedure like this:
CALL check_vals('a','b');
SELECT * FROM T;
Returns:
+----+-----+
| ID | N1 |
+----+-----+
| a | 100 |
| b | 100 |
| c | 90 |
| d | 240 |
+----+-----+
Otherwise, if your goal is to only manipulate the data in a SELECT result, then I would go with P.Salmon's answer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…