{
var(func: has(starring)) {
starring { # Gives you booklist.
haveBook (first: 1, orderdesc: price) {
p as price # Maps from book -> price. Should only have 1 entry.
}
x as sum(p) # Maps from booklist -> price.
}
}
lists(func: uid(x), orderdesc: val(x)) {
haveBook { title, price } # Print the books in the booklist.
}
}
To see more complex query examples, you can see this:
{
var(func: has(starring)) {
starring { # Gives you booklist.
haveBook (first: 1, orderdesc: price) {
p as title # Maps from book -> price. Should only have 1 entry.
}
x as sum(val(p)) # Maps from booklist -> price.
}
}
lists(func: uid(x), orderasc: val(x)) {
haveBook { title, price } # Print the books in the booklist.
}
}
and
{
var(func: has(starring)) {
starring { # Gives you booklist.
haveBook (first: 1, orderdesc: price) {
p as price # Maps from book -> price. Should only have 1 entry.
}
x as sum(val(p)) # Maps from booklist -> price.
}
}
lists(func: uid(x), orderasc: val(x)) {
haveBook { title, price } # Print the books in the booklist.
}
}
it means than you should not use variable in aggregate function sum, all variable should be used just in uid(…) or val(…)
that’s the most important concept for variable