有四个字段分别是CHAR和TEXT类型,想把他们合并后保存到一个里,尝试了很久也不行,我是菜鸟我承认,还请高手指教,谢谢。
我用的SQL语句,不行!
UPDATE table_name SET column1=column1 + " " + column2 + " " + column3 WHERE conditions
5 个解决方案
#1
用concat(s1,s2,...sn)函数,将s1,s2,...,sn连接成字符串.
#2
不好意思上面的可能不可以,我在这里做了一个试验,看看是不是你想要的结果:
mysql> create table c(id int(4),name varchar(20),price float(5,2));
Query OK, 0 rows affected (0.12 sec)
mysql> insert into c values(1,'mysql',20.90);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(2,'sql',23.00);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(3,'oracle',43.50);
Query OK, 1 row affected (0.01 sec)
mysql> select * from c;
+------+--------+-------+
| id | name | price |
+------+--------+-------+
| 1 | mysql | 20.90 |
| 2 | sql | 23.00 |
| 3 | oracle | 43.50 |
+------+--------+-------+
3 rows in set (0.00 sec)
mysql> select group_concat(id,name,price) from c group by id;
+-----------------------------+
| group_concat(id,name,price) |
+-----------------------------+
| 1mysql20.90 |
| 2sql23.00 |
| 3oracle43.50 |
+-----------------------------+
3 rows in set (0.00 sec)
mysql> create table c(id int(4),name varchar(20),price float(5,2));
Query OK, 0 rows affected (0.12 sec)
mysql> insert into c values(1,'mysql',20.90);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(2,'sql',23.00);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(3,'oracle',43.50);
Query OK, 1 row affected (0.01 sec)
mysql> select * from c;
+------+--------+-------+
| id | name | price |
+------+--------+-------+
| 1 | mysql | 20.90 |
| 2 | sql | 23.00 |
| 3 | oracle | 43.50 |
+------+--------+-------+
3 rows in set (0.00 sec)
mysql> select group_concat(id,name,price) from c group by id;
+-----------------------------+
| group_concat(id,name,price) |
+-----------------------------+
| 1mysql20.90 |
| 2sql23.00 |
| 3oracle43.50 |
+-----------------------------+
3 rows in set (0.00 sec)
#3
hy2003fly() 首先非常谢谢你的回答
我的目的是想把组合(连接在一起后)的字符串保存在另一个字段里,能不能请进一步帮我想想办法。再次感谢。
我的目的是想把组合(连接在一起后)的字符串保存在另一个字段里,能不能请进一步帮我想想办法。再次感谢。
#4
UPDATE table_name SET column1=concat(column1,' ',column2,' ',column3) WHERE conditions
#5
问题已经解决,感谢hy2003fly()给出了思路,感谢loveflea(coolwind)给出了方法。感谢你们的帮助,祝你们工作生活愉快顺利。谢谢。
#1
用concat(s1,s2,...sn)函数,将s1,s2,...,sn连接成字符串.
#2
不好意思上面的可能不可以,我在这里做了一个试验,看看是不是你想要的结果:
mysql> create table c(id int(4),name varchar(20),price float(5,2));
Query OK, 0 rows affected (0.12 sec)
mysql> insert into c values(1,'mysql',20.90);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(2,'sql',23.00);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(3,'oracle',43.50);
Query OK, 1 row affected (0.01 sec)
mysql> select * from c;
+------+--------+-------+
| id | name | price |
+------+--------+-------+
| 1 | mysql | 20.90 |
| 2 | sql | 23.00 |
| 3 | oracle | 43.50 |
+------+--------+-------+
3 rows in set (0.00 sec)
mysql> select group_concat(id,name,price) from c group by id;
+-----------------------------+
| group_concat(id,name,price) |
+-----------------------------+
| 1mysql20.90 |
| 2sql23.00 |
| 3oracle43.50 |
+-----------------------------+
3 rows in set (0.00 sec)
mysql> create table c(id int(4),name varchar(20),price float(5,2));
Query OK, 0 rows affected (0.12 sec)
mysql> insert into c values(1,'mysql',20.90);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(2,'sql',23.00);
Query OK, 1 row affected (0.00 sec)
mysql> insert into c values(3,'oracle',43.50);
Query OK, 1 row affected (0.01 sec)
mysql> select * from c;
+------+--------+-------+
| id | name | price |
+------+--------+-------+
| 1 | mysql | 20.90 |
| 2 | sql | 23.00 |
| 3 | oracle | 43.50 |
+------+--------+-------+
3 rows in set (0.00 sec)
mysql> select group_concat(id,name,price) from c group by id;
+-----------------------------+
| group_concat(id,name,price) |
+-----------------------------+
| 1mysql20.90 |
| 2sql23.00 |
| 3oracle43.50 |
+-----------------------------+
3 rows in set (0.00 sec)
#3
hy2003fly() 首先非常谢谢你的回答
我的目的是想把组合(连接在一起后)的字符串保存在另一个字段里,能不能请进一步帮我想想办法。再次感谢。
我的目的是想把组合(连接在一起后)的字符串保存在另一个字段里,能不能请进一步帮我想想办法。再次感谢。
#4
UPDATE table_name SET column1=concat(column1,' ',column2,' ',column3) WHERE conditions
#5
问题已经解决,感谢hy2003fly()给出了思路,感谢loveflea(coolwind)给出了方法。感谢你们的帮助,祝你们工作生活愉快顺利。谢谢。