surfacepipelinetop
Pipelinepipeline · returns table

TOP

Get top N rows by column value

Table-in, table-out — composes downstream of SELECTs.

pipelinellmpipeline-composabletext

Syntax

THEN TOP {{ column }}
THEN TOP({{ column }})
THEN TOP({{ column }}, {{ n }})
THEN TOP({{ column }}, {{ n }}, {{ order }})

Arguments

nametypedescription
columnVARCHAR
n(optional)VARCHAR
order(optional)VARCHAR
_tableTABLE

About

PIPELINE cascade for getting top N rows by a column. Uses pure Python/pandas - no LLM calls. Usage: SELECT * FROM products THEN TOP('sales') -- top 10 by sales SELECT * FROM products THEN TOP('sales', 5) -- top 5 by sales SELECT * FROM products THEN TOP('name', 10, 'asc') -- bottom 10 alphabetically

Examples

Returns the highest-valued rows first by default

SELECT
  *
FROM
  (
    VALUES
      ('A', 10),
      ('B', 25),
      ('C', 7)
  ) AS t (name, amount) THEN TOP ('amount', 2) THEN PYTHON (
    'result = pd.DataFrame({"top_amount":[int(df.iloc[0]["amount"])]})'
  )

Nearby rabbit holes

same domain
Climb back to The Looking Glass