这应该是非常基本但我无法弄清楚.有表'价值'
entity|attribute|value
frank - shirt - red
frank - hat - green
sam - shirt - blue
sam - hat - orange
Run Code Online (Sandbox Code Playgroud)
我怎么设置所有的帽子颜色与衬衫颜色相同,同一个人给坦率的红帽子和山姆蓝帽子.
mem*_*cal 12
我正在寻找解决方案,我想出了这篇文章.但是运行sql导致语法错误.
参考mysql文档 http://dev.mysql.com/doc/refman/5.0/en/update.html 我注意到 - 至少在版本5中 - mysql有不同的语法.
一般声明是:
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 = '...'
Run Code Online (Sandbox Code Playgroud)
小智 5
实际上,您不能在要运行更新的同一表中使用子选择,因此最好的方法是使用联接。
UPDATE users AS target
LEFT JOIN users AS source ON source.id = 1
SET target.name = source.name
WHERE target.id = 2;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13587 次 |
| 最近记录: |