您可以在MySQL中使用CASE将值从1更改为Y。让我们首先创建一个表。创建表的查询如下:
mysql> create table changeValuefrom1toY -> ( -> Id int NOT NULL AUTO_INCREMENT, -> isValidAddress tinyint(1), -> PRIMARY KEY(Id) -> );
现在,您可以使用insert命令在表中插入一些记录。查询如下:
mysql> insert into changeValuefrom1toY(isValidAddress) values(1); mysql> insert into changeValuefrom1toY(isValidAddress) values(0); mysql> insert into changeValuefrom1toY(isValidAddress) values(1); mysql> insert into changeValuefrom1toY(isValidAddress) values(1); mysql> insert into changeValuefrom1toY(isValidAddress) values(1); mysql> insert into changeValuefrom1toY(isValidAddress) values(0); mysql> insert into changeValuefrom1toY(isValidAddress) values(1);
使用select语句显示表中的所有记录。查询如下:
mysql> select *from changeValuefrom1toY;
以下是输出:
+----+----------------+ | Id | isValidAddress | +----+----------------+ | 1 | 1 | | 2 | 0 | | 3 | 1 | | 4 | 1 | | 5 | 1 | | 6 | 0 | | 7 | 1 | +----+----------------+ 7 rows in set (0.00 sec)
以下是与CASE一起使用的查询:
mysql> select *,case -> when isValidAddress=1 THEN 'Y' -> ELSE isValidAddress -> END AS Answer -> from changeValuefrom1toY;
以下是输出:
+----+----------------+--------+ | Id | isValidAddress | Answer | +----+----------------+--------+ | 1 | 1 | Y | | 2 | 0 | 0 | | 3 | 1 | Y | | 4 | 1 | Y | | 5 | 1 | Y | | 6 | 0 | 0 | | 7 | 1 | Y | +----+----------------+--------+ 7 rows in set (0.00 sec)