Table creation: Difference between revisions
Content added Content deleted
No edit summary |
(J: bugfix) |
||
Line 74: | Line 74: | ||
And, here's an example of sorting: |
And, here's an example of sorting: |
||
<lang j> |
<lang j>cols=: [:; {."1@[ <@i.`(<@i.@#@[)@.(=&(<,'*')@]"1 0) cutopen@] |
||
sortBy=: [ /: |
sortBy=: [ /:"1 2 (<__)|:@,. [ }.@{~ cols |
||
from=: cols~ {"0 _ ] |
from=: cols~ {"0 _ ] |
||
select=: |: |
select=: |: |
||
select '*' from stocks sortBy 'price' |
select '*' from stocks sortBy 'price' |
||
┌──────────┬─────┬──────┬────┬─────┐ |
|||
┌─────┬──────┬─────┬────┬──────────┐ |
|||
│date │trans│symbol│qty │price│ |
|||
│trans│symbol│price│qty │date │ |
|||
├──────────┼─────┼──────┼────┼─────┤ |
|||
├─────┼──────┼─────┼────┼──────────┤ |
|||
│2006-01-05│BUY │RHAT │100 │35.14│ |
|||
├──────────┼─────┼──────┼────┼─────┤ |
|||
├─────┼──────┼─────┼────┼──────────┤ |
|||
│2006-03-28│BUY │IBM │1000│45 │ |
|||
├──────────┼─────┼──────┼────┼─────┤ |
|||
├─────┼──────┼─────┼────┼──────────┤ |
|||
│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). |
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). |