使用SQL的位置在两列之间复制数据

时间:2012-01-25 09:11:01

标签: mysql sql

id | one  | two
1  | aa   |
2  | da   |
3  | sds  |
4  | as   |
5  | dfss |
6  | r    |
7  | fd   |

如何将所有数据从“one”复制到“two”,其中长度为1 = = 2使用SQL?在这个例子中应该是:

id | one  | two
1  | aa   | aa
2  | da   | da
3  | sds  |
4  | as   | as
5  | dfss |
6  | r    |
7  | fd   | fd

2 个答案:

答案 0 :(得分:3)

UPDATE your_table SET two = one WHERE LENGTH(one) = 2

答案 1 :(得分:3)

这样的事情应该有用,我想:

UPDATE table SET two = one WHERE LENGTH(one) = 2