Skip to content

Commit

Permalink
Update Cypher.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxiw authored Jan 19, 2025
1 parent a967984 commit 4c9d525
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions demos/guru_scripts/docker/tutorial/4.x/Cypher.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,35 @@ The result is shown in [c11.out](https://github.com/tigergraph/ecosys/blob/maste
[Go back to top](#top)

## Sorting and Limiting Results
`ORDER BY` is a sub-clause following `RETURN` or `WITH`, and it specifies that the output should be sorted and how. `SKIP` defines from which record to start including the records in the output. `LIMIT` constrains the number of records in the output.

In query c12 below, the sorting (`ORDER BY`), skipping (`SKIP`), and limiting (`LIMIT`) operations occur after the WITH clause, which means they are applied to the intermediate results.

The query first aggregates data by counting `tgt2` for each `srcAccountName` using `WITH`. Next, `ORDER BY` sorts the results by `tgt2Cnt` (descending) and `srcAccountName` (descending). `SKIP 1` skips the first record from the sorted intermediate result set. `LIMIT 3` restricts the output to the next 3 records.


Copy [c12.cypher](./cypher/c12.cypher) to your container.

```python
USE GRAPH financialGraph

CREATE OR REPLACE OPENCYPHER QUERY c12(){
MATCH (src)-[e:transfer]-> (tgt1)
MATCH (tgt1)-[e:transfer]-> (tgt2)
WITH src.name AS srcAccountName, COUNT(tgt2) AS tgt2Cnt
ORDER BY tgt2Cnt DESC, srcAccountName DESC
SKIP 1
LIMIT 3
RETURN srcAccountName, tgt2Cnt
}

install query c12

run query c12()
```

The result is shown in [c12.out](https://github.com/tigergraph/ecosys/blob/master/demos/guru_scripts/docker/tutorial/4.x/cypher/c12.out) under `/home/tigergraph/tutorial/4.x/cypher/c12.out`


# Support
If you like the tutorial and want to explore more, join the GSQL developer community at
Expand Down

0 comments on commit 4c9d525

Please sign in to comment.