CAPSTONE 4.3

 

returnN:{[orderColumn;order;N;tab]
// Determine the keywords associated with the ordering required
ascendingOrder: “asc”$order=“top”;

// Order the table by the column provided in ascending or descending order
ordered: tab order by orderColumn xasc ascendingOrder;

// Subset the first/last N records from the newly ordered table
result: ordered[N sublist orderColumn] if order=“top”
ordered[N # orderColumn] if order=“bottom”;

// Output table ordering should be in ascending order
result order by orderColumn xasc orderColumn;
}

if someone helped with the solution it will be helpful for me

If you add your code in a code block it will be much more readable:

Creating q code block with syntax highlighting.

 

What issue are you having getting to a solution?

Errors? What are they? Or incorrect results?

Issue duplicated and resolved: https://community.kx.com/t5/kdb-and-q/help-in-capstone/m-p/13696#M11690