MySql将值从一行复制到另一行 [英] MySql copy value from one row to another
本文介绍了MySql将值从一行复制到另一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这应该是非常基本的,但我不知道.有一个表值"
This should be pretty basic but i can't figure it out. Have a table 'values'
entity|attribute|value
frank - shirt - red
frank - hat - green
sam - shirt - blue
sam - hat - orange
我该如何将同一个人的所有帽子颜色设置为与衬衫颜色相同,以给坦率的红色帽子和sam蓝色的帽子.
how do i set all hats color's to be the same as the shirt color, of the same person to give frank a red hat and sam a blue hat.
推荐答案
我一直在寻找解决方案,因此我发表了这篇文章. 但是,运行sql会导致语法错误.
i was looking for a solution to this and i came up on this post. however running the sql lead to a syntax error.
参考mysql文档 http://dev.mysql.com/doc/refman/5.0/en/update.html 我注意到-至少在版本5中-mysql为此使用了不同的语法.
Refering to the mysql docs http://dev.mysql.com/doc/refman/5.0/en/update.html i noticed - at least in version 5 - mysql has a different syntax for this.
一般声明为:
update table t1, table t2
set t1.field1 = t2.field2, ..., t1.fieldN = t2.fieldN
where t1.someid = t2.someid and t1.fieldX = '...' and t2.fieldY = '...'
这篇关于MySql将值从一行复制到另一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文