我想用for循环创建单个查询
例如,我有一个表1
[id , Name]
[ 1 , X1]
[ 2 , X2]
[ 3 , X3]和第二个表
[id, Name]
[ 5 , Y5]
[ 6 , Y6]
[ 7 , Y7]所有我想要的是有一个新的表与下面的数据
[NewName]
[X1-Y5]
[X1-Y6]
[X1-Y7]
[X2-Y5]
[X2-Y6]
[X1-Y7]
[X3-Y5]
[X3-Y6]
[X3-Y7]我无法创建它,我只能使用first()和last()命令创建表的第一行或最后一行
提前感谢
发布于 2018-07-03 06:14:42
要在新表中获得您想要的组合,请尝试以下javascript函数:
var g = orient.getGraph();
var table1 = g.command("sql","select from table1");
var table2 = g.command("sql","select from table2");
for(i = 0; i < table1.length; i++)
{
for(j = 0; j < table2.length; j++)
{
g.command("sql","insert into table3(newName) values ('"+ table1[i].getRecord().field("name") +" - "+ table2[j].getRecord().field("name") +"')")
}
}您可以在SQL中这样调用它:
select function_name()这样你就有了一种连接表,如果这是你的意图不是正确的方式,因为在OrientDB中没有连接,相反,你可以使用边缘,链接...
如果你想知道如何做你想做的事情,你可以试试这个javascript函数:
var g = orient.getGraph();
var table1 = g.command("sql","select from table1");
var table2 = g.command("sql","select from table2");
for(i = 0; i < table1.length; i++)
{
for(j = 0; j < table2.length; j++)
{
g.command("sql","create edge connection from "+ table1[i].getId() +" to "+ table2[j].getId() +"")
}
}和以前一样,您可以在SQL中这样调用它:
select function_name()希望能有所帮助
问候
https://stackoverflow.com/questions/51122744
复制相似问题