dream2891 2018-08-02 05:16
浏览 235

INSERT使用SELECT语句,并在MySQL中同时向结果的每一行添加一个变量值[duplicate]

This question already has an answer here:

I have a table nameValue that has 5 columns (Id,val,firstName,lastName,age). I use a select statement that gives firstName,lastName, age in multiple rows, lets say it returns 5 rows. Id is Auto-Increment. I want to add val to each of the 5 rows returned.

$val=55; INSERT INTO nameValue (val,firstName,lastName,age) VALUES($val, SELECT fName,lName,age FROM nameAge WHERE age<25); something like this where we are insert same variable $val to each of the 5 rows returned by the select statement.

</div>
  • 写回答

1条回答 默认 最新

  • doukui7574 2018-08-02 05:17
    关注

    Thats the wrong way. Try this -

    INSERT INTO nameValue (val,firstName,lastName,age)
    SELECT $val, fName,lName,age FROM nameAge WHERE age < 25
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度