Skip to content

Commit 6c33b40

Browse files
subclause clarification and formating
1 parent 1274352 commit 6c33b40

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

modules/ROOT/pages/clauses/with.adoc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ RETURN chocolateCustomers,
135135
Variable `p` not defined
136136
----
137137

138-
[NOTE]
139-
The `WHERE` subclause is not limited in the same way by preceding `WITH` clauses.
140-
For more information, see xref:clauses/where.adoc#where-and-with[Using `WHERE` after `WITH`].
141-
142138
.Retain all variables with `WITH *`
143139
[source, cypher]
144140
----
@@ -256,9 +252,7 @@ ORDER BY price
256252
|===
257253

258254
[NOTE]
259-
The `LET` clause can also be used to assign values to variables.
260-
However, unlike `WITH`, it cannot drop variables from the query scope.
261-
As a result, `LET` can be used to chain expressions in a more clear and concise manner than `WITH`.
255+
The `LET` clause can be used to assign values to variables and to chain expressions more clearly and concisely than `WITH`.
262256
For more information, see xref:clauses/let.adoc#chaining-expressions[`LET` -> Chaining expressions].
263257

264258
[[aggregations]]
@@ -362,17 +356,18 @@ ORDER BY discountRates
362356
[[ordering-pagination]]
363357
== Ordering and pagination
364358

365-
`WITH` can order and paginate results before they are passed on to subsequent clauses.
359+
`WITH` can order and paginate results if used together with the xref:clauses/order-by.adoc[`ORDER BY`], xref:clauses/limit.adoc[`LIMIT`], and xref:clauses/skip.adoc[`SKIP`] subclauses.
360+
If so, these subclauses be understood as part of the result manipulation performed by `WITH` -- not as a standalone clause -- before results are passed on to subsequent clauses.
366361

367-
In the below query, the results are ordered in a descending order by which `Customer` has spent the most using xref:clauses/order-by.adoc[`ORDER BY`] before they are passed on to the final `RETURN` clause.
362+
In the below query, the results are ordered in a descending order by which `Customer` has spent the most using `ORDER BY` before they are passed on to the final `RETURN` clause.
368363

369364
.Order results with `ORDER BY`
370365
[source, cypher]
371366
----
372367
MATCH (c:Customer)-[:BUYS]->(p:Product)
373368
WITH c,
374369
sum(p.price) AS totalSpent
375-
ORDER BY totalSpent DESC
370+
ORDER BY totalSpent DESC
376371
RETURN c.firstName AS customer, totalSpent
377372
----
378373

@@ -392,7 +387,7 @@ RETURN c.firstName AS customer, totalSpent
392387
2+d|Rows: 7
393388
|===
394389

395-
In the next example, xref:clauses/limit.adoc[`LIMIT`] is used to only retain the top 3 customers with the highest `totalSpent` values in the result set after ordering.
390+
In the next example, `LIMIT` is used to only retain the top 3 customers with the highest `totalSpent` values in the result set after ordering.
396391
Then, the xref:clauses/set.adoc[`SET`] assigns a new property (`topSpender = true`) to those customers who have spent the most.
397392

398393
.Limit results with `LIMIT`
@@ -401,8 +396,8 @@ Then, the xref:clauses/set.adoc[`SET`] assigns a new property (`topSpender = tru
401396
MATCH (c:Customer)-[:BUYS]->(p:Product)
402397
WITH c,
403398
sum(p.price) AS totalSpent
404-
ORDER BY totalSpent DESC
405-
LIMIT 3
399+
ORDER BY totalSpent DESC
400+
LIMIT 3
406401
SET c.topSpender = true
407402
RETURN c.firstName AS customer,
408403
totalSpent,
@@ -420,7 +415,7 @@ RETURN c.firstName AS customer,
420415
3+d|Rows: 3
421416
|===
422417

423-
xref:clauses/skip.adoc[`SKIP`] can be used after a `WITH` clause to discard rows from the result set.
418+
`SKIP` can be used after a `WITH` clause to discard rows from the result set.
424419
Below, `SKIP` excludes the first 3 rows in the ordered result set (i.e. the 3 `Customer` nodes with highest `totalSpent` value) and assigns a `false` value to the new `topSpender` property of the remaining `Customer` nodes.
425420

426421
.Exclude results with `SKIP`
@@ -429,8 +424,8 @@ Below, `SKIP` excludes the first 3 rows in the ordered result set (i.e. the 3 `C
429424
MATCH (c:Customer)-[:BUYS]->(p:Product)
430425
WITH c,
431426
sum(p.price) AS totalSpent
432-
ORDER BY totalSpent DESC
433-
SKIP 3
427+
ORDER BY totalSpent DESC
428+
SKIP 3
434429
SET c.topSpender = false
435430
RETURN c.firstName AS customer,
436431
totalSpent,
@@ -459,8 +454,8 @@ The second `MATCH` clause then matches only from that single product to find all
459454
----
460455
MATCH (:Supplier {name: 'Foodies Inc.'})-[:SUPPLIES]->(p:Product)
461456
WITH p
462-
ORDER BY p.price DESC
463-
LIMIT 1
457+
ORDER BY p.price DESC
458+
LIMIT 1
464459
MATCH (p)<-[:BUYS]-(c:Customer)
465460
RETURN p.name AS product
466461
p.price AS price,
@@ -481,14 +476,16 @@ RETURN p.name AS product
481476
[[filter-results]]
482477
== Filter results
483478

484-
`WITH` can be used in conjunction with `WHERE` to filter results.
479+
`WITH` can be followed by the xref:clauses/where.adoc[`WHERE`] subclause to filter results.
480+
Similar to the subclauses used for xref:clauses/with.adoc#ordering-pagination[ordering and pagination], `WHERE` should be understood as part of the result manipulation performed by `WITH` -- not as a standalone clause -- before the results are passed on to subsequent clauses.
481+
For more information, see xref:clauses/where.adoc#where-and-with[Using `WHERE` after `WITH`].
485482

486483
.Filter using `WITH` and `WHERE`
487484
[source, cypher]
488485
----
489486
UNWIND [1, 2, 3, 4, 5, 6] AS x
490487
WITH x
491-
WHERE x > 2
488+
WHERE x > 2
492489
RETURN x
493490
----
494491

@@ -504,7 +501,7 @@ RETURN x
504501
1+d|Rows: 4
505502
|===
506503

507-
In the below query, the `WITH` and `WHERE` are used to filter out any `Supplier` nodes whose `totalSales` is less than `1000`.
504+
In the below query, `WITH` and `WHERE` are used to filter out any `Supplier` nodes whose `totalSales` is less than `1000`.
508505
Note the use of `DISTINCT` inside `collect()` to remove any duplicate `Customer` nodes.
509506

510507
.Filter property values using `WITH` and `WHERE`
@@ -514,7 +511,7 @@ MATCH (s:Supplier)-[:SUPPLIES]->(p:Product)<-[:BUYS]-(c:Customer)
514511
WITH s,
515512
sum(p.price) AS totalSales,
516513
count(DISTINCT c) AS uniqueCustomers
517-
WHERE totalSales > 1000
514+
WHERE totalSales > 1000
518515
RETURN s.name AS supplier,
519516
totalSales,
520517
uniqueCustomers

0 commit comments

Comments
 (0)