以下SQL语句有效并按预期执行:
SELECT r1.rs_objectidentifier AS parent,
r2.rs_objectidentifier AS child,
"satisfies" AS relation,
0 AS root,
0 AS leaf
FROM rsdata r1,
rsdata r2
WHERE r1.weeknumber="1410"
AND r1.weeknumber=r2.weeknumber
AND r1.rs_variant=r2.rs_variant
AND r1.rs_inrsobjectidentifieronelevel != ""
AND r1.rs_inrsobjectidentifieronelevel != "Unknown"
AND find_in_set(r2.rs_objectidentifier, r1.rs_inrsobjectidentifieronelevel)
UNION
SELECT rsdata.rs_objectidentifier AS parent,
"" AS child,
"satisfies" AS relation,
0 AS root,
0 AS leaf
FROM rsdata
WHERE rsdata.weeknumber="1410"
AND (rsdata.RS_InRSObjectIdentifierOneLevel = ""
OR rsdata.RS_InRSObjectIdentifierOneLevel = "Unknown")
当我使用以下insert语句添加select时,我得到一个SQL语法错误:
insert into traceability
select中的列与表中的字段匹配(据我所知)。该表看起来像:
CREATE TABLE `traceability` ( `Parent` varchar(50) default NULL,
`Child` varchar(50) default NULL, `Relation` varchar(20) default
NULL, `Root` tinyint(1) default NULL, `Leaf` tinyint(1) default
NULL, UNIQUE KEY `Traceability_UI1` (`Parent`,`Child`,`Relation`) )
ENGINE=MyISAM DEFAULT CHARSET=latin1
为什么在插入语句添加时会出现MySQL语法错误???
以下错误(信息量不大)是......
1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'insert into
traceability select r1.rs_objectidentifier as parent, r2.rs_objec' at line 2
答案 0 :(得分:0)
试试这个
insert into traceability(Parent,Child,Relation,Root,Leaf) Select .....
答案 1 :(得分:0)
行。解决方案非常简单。 SQL是一组SQL语句的一部分。上面发布的声明遗失了; (终止语句)所以进入下一个语句,因此抛出语法错误.... 头脑羞愧