我正在一个项目中,我想从另一个表插入数据,并且还要在连接函数中使用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);
答案 0 :(得分:0)
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);
您错过了一些括号,并且那里还有些昏迷。除了那些查询之外,该查询应该可以正常工作。
答案 1 :(得分:0)
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);
因为我没有足够的代表,所以无法评论pr1nc3的答案,但是他的查询需要进行一些细微调整,并希望这会起作用。 无需从地址中选择建筑物,城市和密码,您只需选择相应字段的concat()结果即可。您也没有选择servicecategory字段。