Tabular OperatorsFilter Operators
top
Returns the top N rows sorted by the specified columns.
Returns the top N rows sorted by the specified columns. More memory-efficient than sort+take for large datasets.
Syntax
top N by column [asc|desc] [nulls first|last], ...Return top N rows sorted by columns with optional null placement. Default sort order is descending (desc).
Parameters
| Name | Description |
|---|---|
| count | Maximum number of rows to return |
| column | Column or expression to sort by. Default order is descending if not specified. |
| nulls first | last |
Examples
Example 1
datatable(raid:string, loot_silver:long, monastery:string)[
"793 Lindisfarne", 500, "Lindisfarne",
"845 Paris", 7000, "Saint-Germain",
"860 Winchester", 300, "Winchester",
"866 York", 1200, "York Minster",
"911 Normandy", 4000, "Rouen"
]
| top 3 by loot_silver| raid (string) | loot_silver (long) | monastery (string) |
|---|---|---|
| 845 Paris | 7000 | Saint-Germain |
| 866 York | 1200 | York Minster |
| 911 Normandy | 4000 | Rouen |
Example 2
datatable(warrior:string, battles:long)[
"Ragnar", 30,
"Bjorn", 15,
"Ivar", 22,
"Lagertha", 18,
"Harald", 25
]
| top 2 by battles asc| warrior (string) | battles (long) |
|---|---|
| Bjorn | 15 |
| Lagertha | 18 |