用于循环的OrientDB

用于循环的OrientDB,orientdb,Orientdb,我想用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()命令来创建表的fir

我想用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()命令来创建表的first或alst行


提前感谢

要在新表中获得所需的组合,请尝试以下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") +"')")
  }
}
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() +"")
  }
}
这样,您就有了一种联接表,如果这是您的意图,那么由于OrientDB中没有联接,因此不是正确的联接方式,相反,您可以使用Edge、Link

如果您正在寻找如何做自己想做的事情,可以尝试以下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") +"')")
  }
}
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() +"")
  }
}
希望能有帮助


关于

不确定我是否正确:您是否试图在两个类之间创建边?或者你正在尝试进行某种类型的联接吗?不是,这是一个simlpe SQL表。我正在尝试只使用一个查询来实现这一点