我想在KDB中运行CASE WHEN查询,并从每个类别中选择可用后付费限额利用率最高的顶级客户。 我可以通过支出获得最高客户,但我还希望百分比利用率来自于某些变量(到目前为止,将其视为硬编码)
我尝试了以下操作:
`category xasc `amount xdesc `date xasc select category,date,custName,amount,postpaidLimit,percentageUtilization:amount%postpaidLimit from (select sum amount by category,date,amount,custName from Orders where date within(2019.05.12;2019.06.13) and amount in (`ONLINE;`OFFLINE) ) where ({x in 1#x};i) fby category
postpaidLimit :
categoty1 : 1000
categoty2 : 2000
categoty3 : 3000
categoty4 : 4000
预期结果应该是每个类别的头号客户,并列出可用限制的花费
category date custName amount postpaidLimit percentageUtilization
categoty1 2019.05.12 A 500 1000 50%
categoty2 2019.05.12 B 1500 2000 75%
categoty3 2019.05.12 C 1000 3000 33%
categoty4 2019.05.12 D 1000 4000 25%