Table creation: Difference between revisions

J: bugfix
No edit summary
(J: bugfix)
Line 74:
And, here's an example of sorting:
 
<lang j>cols=: cols=: [:; {."1@[ <@i.`(<@i.@#@[)@.(=&(<,'*')@]"1 0) cutopen@]
sortBy=: [ /:"1 a:2 (<__)|:@,. [ }.@{~ cols
from=: cols~ {"0 _ ]
select=: |:
 
select '*' from stocks sortBy 'price'
┌──────────┬─────┬──────┬────┬─────┐
┌─────┬──────┬─────┬────┬──────────┐
│date │trans│symbol│qty │price│
│trans│symbol│price│qty │date │
├──────────┼─────┼──────┼────┼─────┤
├─────┼──────┼─────┼────┼──────────┤
│BUY│2006-01-05│BUY │RHAT │100 │35.14│100 │2006-01-05│14│
├──────────┼─────┼──────┼────┼─────┤
├─────┼──────┼─────┼────┼──────────┤
│BUY│2006-03-28│BUY │IBM │45│1000│45 │1000│2006-03-28│
├──────────┼─────┼──────┼────┼─────┤
├─────┼──────┼─────┼────┼──────────┤
│2006-04-06│SELL │IBM │500 │53 │
│BUY │MSOFT │72 │1000│2006-04-05│
├──────────┼─────┼──────┼────┼─────┤
├─────┼──────┼─────┼────┼──────────┤
│2006-04-05│BUY │MSOFT │1000│72 │
│SELL │IBM │53 │500 │2006-04-06│
└──────────┴─────┴──────┴────┴─────┘</lang>
└─────┴──────┴─────┴────┴──────────┘</lang>
 
Note that this particular example is both overly general in some senses (for example, named column handling has features not demonstrated here) and overly specific in others (for example, I did not implement sort in descending order).
6,951

edits