我有一个名为nominator的数据库,其中包含一些字段
它有一个名为'noinatedUnder'的字段,如何显示该字段的inS数量
这是原始文本 从指定者中选择
{
"result": [
{
"@type": "d",
"@rid": "#73:2",
"@version": 2,
"@class": "Nominator",
"isTemp": "true",
"id": "JJRXW",
"Email": "testuser@test.com",
"Name": "nijeesh",
"Phone": "7894561234",
"school": "#65:2",
"in_noinatedUnder": [
"#161:1",
"#162:1",
"#163:1",
"#164:0",
"#165:0",
"#166:0",
"#167:0",
"#168:0",
"#161:0",
"#162:0",
"#163:0"
],
"@fieldTypes": "school=x,in_noinatedUnder=g"
},
{
"@type": "d",
"@rid": "#74:0",
"@version": 1,
"@class": "Nominator",
"isTemp": "true",
"id": "SU7SV",
"Email": "npms@school.com",
"Name": "pon muthu",
"Phone": "7778455215",
"school": "#65:2",
"@fieldTypes": "school=x"
},
{
"@type": "d",
"@rid": "#75:1",
"@version": 1,
"@class": "Nominator",
"isTemp": "true",
"id": "4DZ86",
"Email": "sivaraj@testschool.com",
"Name": "sivaraj",
"Phone": "7788899445",
"school": "#65:2",
"@fieldTypes": "school=x"
},
{
"@type": "d",
"@rid": "#76:1",
"@version": 1,
"@class": "Nominator",
"isTemp": "true",
"id": "HFQJ1",
"Email": "klndk@knvd.com",
"Name": "dbhbsd",
"Phone": "8656548745",
"school": "#65:2",
"@fieldTypes": "school=x"
}
],
"notification": "Query executed in 6.12 sec. Returned 4 record(s)"
}
在第一个条目中有11个在in->指定的区域内输入,0在其他所有区域如何使用sql为每个字段选择此数字
它应该打印
-----------
count | ----------
11
0
0
0
我确实使用php获得了结果
$query = "select * from `Nominator`";
$result = runquery($query);
$a = array();
for($i=0;$i<sizeof($result);$i++)
{
echo '<p>';
echo isset($result[$i]->oData->in_noinatedUnder)?sizeof($result[$i]->oData->in_noinatedUnder):0;
echo '</p>';
}
function runquery($query)
{
$client = new PhpOrient();
$client->hostname = 'localhost';
$client->port = 2424;
$client->username = 'root';
$client->password = 'hello';
$client->connect();
$client->dbOpen('tabe');
$result = $client->query($query);
$json = json_decode(json_encode($result));
if (sizeof($json) > 0) {
return $json;
} else {
return false;
}
}
那么有没有办法直接从sql获取计数呢,比如从指定者中选择计数(*)给出了提名者的数量
答案 0 :(得分:1)
要获取顶点数,请尝试以下查询:
select in().size() from <class-name>
希望它有所帮助。
此致