如何计算字段中的 in 数

How to Count Number of in in a field

我有一个名为 nominator 的数据库,其中有一些字段

它有一个名为 'noinatedUnder' 的 in 字段,我如何显示该字段的 inS 数量

这是原始文本 SELECT 来自提名人

{
    "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)"
}

在此第一个条目中,in->nominated under area 中有 11 个条目,其他所有条目均为 0 如何 select 这个数字对每个字段使用 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 自己获取计数,比如 select 来自提名人的计数(*) 给出了提名人的计数

要获取 in 中的顶点数,请尝试此查询:

select in().size() from <class-name>

希望对您有所帮助。

此致