MySQL 使用 select 更新表中的多列和记录
我刚刚向我正在处理的表中添加了两列,并希望根据另一列的值将数值放入这两列中。我需要对数据库(MySQL)中的所有记录执行此操作,有人可以帮我吗?
表(t1)看起来像
spectra (varchar, primary key),
value REAL,(This is the one to use)
new_val 1 REAL
new_val 2 REAL
我认为它应该看起来像这样;
update t1 set (new_val1,new_val2)=(select value*1.5,value*2 from t1) as t2 where t1.spectra=t2.spectra;
请问有什么建议吗? 谢谢, 詹姆斯
I've just added two columns to a table I was working on, and want to put numerical values in those two columns based on the value of another column. I need to do this for all of the records in the database (MySQL), can someone help me with this please?
The table (t1) looks like
spectra (varchar, primary key),
value REAL,(This is the one to use)
new_val 1 REAL
new_val 2 REAL
I'm thinking it should look something like;
update t1 set (new_val1,new_val2)=(select value*1.5,value*2 from t1) as t2 where t1.spectra=t2.spectra;
Any suggestions please?
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所需要的只是:
All you need is: