简体   繁体   English

如何在INSERT语句和CONCAT()函数中使用多个SELECT语句

[英]How to use multiple SELECT statement in INSERT statement and also in CONCAT() function

I'm working on a project where i want to insert data from another table and also use select statement in concatenate function but i can't understand ? 我正在一个项目中,我想从另一个表插入数据,并在连接函数中使用select语句,但我听不懂?

INSERT INTO c_order
 (oid,cid,servicename,servicetype,servicecategory,price,address,date,status,time)
VALUES
  ('qw121','121',(select servicename,servicetype,price, from inner_subservice where inssid=1),(select building,city,pincode CONCAT(building,'',city,'',pincode) as fullname from address where cid='121',now(),'ongoing',null);

1064 - You have an error in your SQL syntax; 1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from inner_subservice where inssid=1),(select building,city,pincode CONCAT(build' at line 1 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'from inner_subservice where inssid = 1)附近使用(选择建筑物,城市,密码CONCAT(build)在第1行)

INSERT INTO c_order(oid,cid,servicename,servicetype,servicecategory,price,address,date,status,time)
VALUES("qw121","121",
(select servicename,servicetype,price from inner_subservice where inssid=1),
(select building,city,pincode, CONCAT(building,'',city,'',pincode) as fullname from address where cid='121'),now(),
'ongoing',null);

You were missing some parenthesis and you had some extra comas there. 您缺少括号,并且那里还有一些昏迷。 Apart from those this query should work fine. 除那些之外,此查询应该运作良好。

INSERT INTO c_order(oid,cid,servicename,servicetype,servicecategory,price,address,date,status,time) VALUES("qw121","121",(select servicename,servicetype,servicecategory,price from inner_subservice where inssid=1),(select CONCAT(building,'',city,'',pincode) as fullname from address where cid='121'),now(),'ongoing',null);

Couldn't comment on pr1nc3's answer because i don't have enough rep, but his query needed a small tweak and hopefully this would work. 无法对pr1nc3的答案发表评论,因为我没有足够的代表,但是他的查询需要稍作调整,并希望这会起作用。 Instead of selecting building, city and pincode from address you only need to select the concat() result of the respective fields. 无需从地址中选择建筑物,城市和密码,您只需选择相应字段的concat()结果即可。 Also you didn't select servicecategory field. 您也没有选择servicecategory字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM