Thursday, November 3, 2016

one way to pivot table

trade table:

stock side amount
----------------------
`ibm b 100
`ibm s 200
`appl b 300

-- sql server syntax
select stock, sum(iif(side='b', amount, 0)) as b, sum(iif(side='s', amount, 0)) as s
 from trade
 group by stock;

stock b s
------------------
`ibm 100 200
`aapl 300 0

Tuesday, November 1, 2016

Column names as parameters to functions

http://code.kx.com/wiki/Cookbook/ProgrammingIdioms#Column_names_as_parameters_to_functions