这部分主要是查询块、查询变量、聚合操作

多名称查询

实际上就是类似多个查询数据的拼接

格式:
{
caro(func: allofterms(name@en, "Marc Caro")) {
name@en
director.film {
name@en
}
}
jeunet(func: allofterms(name@en, "Jean-Pierre Jeunet")) {
name@en
director.film {
name@en
}
}
}

查询变量

类似graphql 总的input 变量,但是查询变量更方便,可以理解为sql 的存储过程,或者编程中的函数

var_name as some_block { ... }

查询变量数据的引用

查询变量的数据可以传递给子查询block 使用,这点相比graphql 的方式有很大的方便

参考格式:
{
coactors(func:allofterms(name@en, "Jane Campion")) @cascade {
JC_films as director.film { # JC_films = all Jane Campion's films
starting_movie: name@en
starring {
JC_actors as performance.actor { # JC_actors = all actors in all JC films
actor : name@en
actor.film {
performance.film @filter(not uid(JC_films)) {
film_together : name@en
starring {
# find a coactor who has been in some JC film
performance.actor @filter(uid(JC_actors)) {
coactor_name: name@en
}
}
}
}
}
}
}
}
}

指变量(min max)

使用min max 可以获取变量的最大或者最小指

参考格式:
{
q(func: allofterms(name@en, "Ang Lee")) {
director.film {
uid
name@en # Count the number of starring edges for each film
num_actors as count(starring) # In this block, num_actors is the value calculated for this film.
# The film with uid and name
} # Here num_actors is a map of film uid to value for all
# of Ang Lee's films
#
# It can't be used directly, but aggregations like min and max
# work over all the values in the map most_actors : max(val(num_actors))
} # to use num_actors in another query, make sure it's done in a context
# where the film uid to value map makes sense.
}

指变量(sum avg)

可以获取变量的sum 以及avg

参考格式:
{
ID as var(func: allofterms(name@en, "Steven Spielberg")) { # count the actors and save to a variable # average as ...
} # average is a map from uid to value so it must be used in a context
# where the map makes sense. Because query block avs works over the UID
# of Steven Spielberg, the value variable has the value we expect.
avs(func: uid(ID)) @normalize {
name : name@en
# get the average
# also count the movies
}
}

指变量 filter order

指变量可以应用filter以及order 操作

参考格式:
{
ID as var(func: allofterms(name@en, "Steven")) {
director.film {
num_actors as count(starring)
}
average as avg(val(num_actors))
} avs(func: uid(ID), orderdesc: val(average)) @filter(ge(val(average), 40)) @normalize {
name : name@en
average_actors : val(average)
num_films : count(director.film)
}
}

指变量 math

dgraph 内置math 函数操作,可以进行一些常见的+ / - 以及sin 。。。。 操作

参考格式:
{
var(func:allofterms(name@en, "Jean-Pierre Jeunet")) {
name@en
films as director.film {
stars as count(starring)
directors as count(~director.film)
ratio as math(stars / directors)
}
} best_ratio(func: uid(films), orderdesc: val(ratio)){
name@en
stars_per_director : val(ratio)
num_stars : val(stars)
}
}

groupby 操作

类似sql 的groupby 操作,groupby 代码块内部操作只能应用到聚合函数上,同时count 只能
应用到uid 上,同时可以方便的通过变量应用到其他查询中

参考格式:
{
var(func:allofterms(name@en, "Steven Spielberg")) {
director.film @groupby(genre) {
a as count(uid)
}
} byGenre(func: uid(a), orderdesc: val(a)) {
name@en
num_movies : val(a)
}
}

参考资料

https://tour.dgraph.io/blocksvars/1/
https://github.com/rongfengliang/dgraph-docker-compose-deploy

 
 
 
 

dgraph 基本查询语法 三的更多相关文章

  1. dgraph 基本查询语法 一

    dgraph 的查询语法是在graphql 上的扩展,添加了新的支持,同时官方提供了一个 学习的网站 https://tour.dgraph.io/ 基本环境(cluster 模式的) 参考 gith ...

  2. dgraph 基本查询语法 二

    这部分主要是mutation 操作,(就是增加.删除操作) 参考git 项目 https://github.com/rongfengliang/dgraph-docker-compose-deploy ...

  3. ThinkPHP 数据库操作(三) : 查询方法、查询语法、链式操作

    查询方法 条件查询方法 where 方法 可以使用 where 方法进行 AND 条件查询: Db::table('think_user') ->where('name','like','%th ...

  4. Entity Framework 基于方法的查询语法

      实体框架(Entity Framework )是 ADO.NET 中的一套支持开发面向数据的软件应用程序的技术. LINQ to Entities 提供语言集成查询 (LINQ) 支持,它允许开发 ...

  5. LINQ to Entities 查询语法

    转自: http://www.cnblogs.com/asingna/archive/2013/01/28/2879595.html 实体框架(Entity Framework )是 ADO.NET  ...

  6. Linq 标准查询操作符三

    本文介绍了LINQ标准查询操作符.没有这些操作符,LINQ就不会存在.本文为理解这些操作符的功能提供了很好的基础.了解它们将会很有帮助,因为LINQ的各种Provider都是基于这些操作符来完成各自丰 ...

  7. Lucene学习总结之八:Lucene的查询语法,JavaCC及QueryParser

    一.Lucene的查询语法 Lucene所支持的查询语法可见http://lucene.apache.org/java/3_0_1/queryparsersyntax.html (1) 语法关键字 + ...

  8. solr总结 第六部分:solr查询语法

    1.基本查询语法 q:全文查询.schema.xml里面定义了如下两块.eg q=ibm即表示org_name或者org_weisite里面出现ibm的document都可以被匹配到.KeyWords ...

  9. EF基于方法的查询语法

    实体框架(Entity Framework )是 ADO.NET 中的一套支持开发面向数据的软件应用程序的技术. LINQ to Entities 提供语言集成查询 (LINQ) 支持,它允许开发人员 ...

随机推荐

  1. mycat分布式mysql中间件(自增主键)

    一.全局序列号 全局序列号是MyCAT提供的一个新功能,为了实现分库分表情况下,表的主键是全局唯一,而默认的MySQL的自增长主键无法满足这个要求.全局序列号的语法符合标准SQL规范,其格式为:nex ...

  2. codeforces 993c//Careful Maneuvering// Codeforces Round #488 by NEAR (Div. 1)

    题意:x轴-100和+100的有敌人飞船,纵坐标由输入数据给出,我方有2飞船在x轴0,y坐标待定.0时刻时敌人同时向我方2飞船发出光线,光线会穿透飞船打到敌人自己,问2飞船放在哪敌人损失最大? 假如- ...

  3. Confluence 6 使用 LDAP 授权连接到 Confluence 内部目录

    希望连接一个内部目录但是使用 LDAP 检查登录授权: 在屏幕的右上角单击 控制台按钮 ,然后选择 General Configuration 链接. 单击左侧面板上面的 用户目录(User Dire ...

  4. splay板子

    1, splay的一些基本操作. 使用前要插入$-INF,+INF$保证每个点的前驱后继存在. $get$函数在$x$存在时, 调用后, 根为$x$, 否则根为$x$的前驱或后继 const int ...

  5. php date()

    PHP Date() 函数把时间戳格式化为更易读的日期和时间. date(format,timestamp) format:显示时间的格式.  timestamp:可选.规定时间戳.默认是当前时间和日 ...

  6. 5.4 使用 Razor 表达式

    以下内容主要展示 Razor 所支持的各种表达式,以及如何用它们来创建视图的内容. 在一个好的 MVC 框架应用程序中,动作方法与视图的作用是清晰.分离的.其规则很简单,如表所示: 组件 要做的事 不 ...

  7. C++:线程(std::thread)

    1.创建一个线程 创建线程比较简单,使用std的thread实例化一个线程对象就创建完成了,示例: #include <iostream> #include <thread> ...

  8. Android开发——1轻松战胜开发环境

    写在前头的话:鄙人乃2016年本科毕业的程序yuan一枚,大学阶段从未学过安卓,java也是一知半解,回想这一年半的开发生涯真的是相当悲壮.你要是问我喜欢开发吗,当然确定一定以及肯定地告诉你不喜欢啊! ...

  9. windows 环境下python 安装 pypcap 并用pyinstaller打包到exe,解决DLL 加载失败。

    安装 PYQT5 pypcap 环境: windows10_x64 python3.6.3 pycharm2017.2.4 备注: 需要安装 Visual C++ Build Tools 2015 可 ...

  10. Runtime的基本运用

    一.什么是runtime(也就是所谓的“运行时”,因为是在运行时实现的.)           1.runtime是一套底层的c语言API(包括很多强大实用的c语言类型,c语言函数);  [runti ...