简体   繁体   English

在orientdb中如何从数据集中选择任意5行

[英]In orientdb how to select any 5 rows from set of data

My database class is having 1000 rows out of which i want when i fire query it should give me any arbitrary 5 rows on each hit, can or can not be unique. 我的数据库类有1000行,当我触发查询时我想要它应该在每次命中时给我任意5行,可以是也可以不是唯一的。

What i need to add in query for same? 我需要在查询中添加什么?

You can use this simple JavaScript function which will take all records from v and return 5 random: 您可以使用这个简单的JavaScript函数,该函数将从v获取所有记录并随机返回5:

var g=orient.getDatabase(); 
var b=g.query("select from v");
var result = [];
for(i=1;i<=5;i++){
   item=b[Math.floor(Math.random()*b.length)]
   result.push(item);
}
return result;

Than you can query for results using: 您可以使用以下方法查询结果:

select expand(result) from (select randomFunc() as result)

See screenshots from Studio: 查看Studio的屏幕截图:

在此输入图像描述 在此输入图像描述

Hope it will help you. 希望它会对你有所帮助。

No, currently there isn't a random function. 不,目前没有随机功能。 You could see this link . 你可以看到这个链接

Hope it helps. 希望能帮助到你。

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

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