在MySQL中为自定义列设置多个值?
为此,您可以使用UNION ALL。让我们首先创建一个表-
mysql> create table DemoTable1987(
UserValue int
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1987 values(4);mysql> insert into DemoTable1987 values(5);
mysql> insert into DemoTable1987 values(6);
mysql> insert into DemoTable1987 values(7);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1987;
这将产生以下输出-
+-----------+| UserValue |
+-----------+
| 4 |
| 5 |
| 6 |
| 7 |
+-----------+
4 rows in set (0.00 sec)
这是为自定义列设置多个值的查询-
mysql> select UserValue,(UserValue*100) as NewValue from DemoTable1987union all
select UserValue,(UserValue*50) as NewValue from DemoTable1987
order by UserValue;
这将产生以下输出-
+-----------+----------+| UserValue | NewValue |
+-----------+----------+
| 4 | 400 |
| 4 | 200 |
| 5 | 500 |
| 5 | 250 |
| 6 | 300 |
| 6 | 600 |
| 7 | 350 |
| 7 | 700 |
+-----------+----------+
8 rows in set (0.14 sec)
以上是 在MySQL中为自定义列设置多个值? 的全部内容, 来源链接: utcz.com/z/316106.html