SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE ROOMS ( room_id INTEGER PRIMARY KEY, floor INTEGER, light_is_on VARCHAR(1) ); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (101, 1, '0'); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (102, 1, '0'); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (103, 1, '1'); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (201, 2, '0'); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (202, 2, '0'); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (301, 3, '1'); INSERT INTO ROOMS (room_id, floor, light_is_on) VALUES (302, 3, '1'); MERGE INTO ROOMS r USING (SELECT room_id FROM ROOMS WHERE MOD(room_id, 2) = 1) o ON (r.room_id = o.room_id) WHEN MATCHED THEN UPDATE SET r.light_is_on = CASE WHEN r.light_is_on = '0' THEN '1' ELSE '0' END; select * from ROOMS;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear