LoginSignup
1
1

More than 5 years have passed since last update.

MySQLでフリップフロップ

Posted at

以下のようなSQL文で、01を交互に入れ替えることができる。

UPDATE flip_flop SET value = value xor 1;

mysql> CREATE TABLE flip_flop (value int not null);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO flip_flop VALUES (0);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM flip_flop;
+-------+
| value |
+-------+
|     0 |
+-------+
1 row in set (0.00 sec)

mysql> UPDATE flip_flop SET value = value xor 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM flip_flop;
+-------+
| value |
+-------+
|     1 |
+-------+
1 row in set (0.00 sec)

mysql> UPDATE flip_flop SET value = value xor 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM flip_flop;
+-------+
| value |
+-------+
|     0 |
+-------+
1 row in set (0.00 sec)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1