2022.04.06 10:13 AM
Hey Qbies,
I have a table containing for multiple symbols that I'm looking to count rows...
For example:
symbol | symbol count | dataset count
aapl | 1 | 1
aapl| 2 | 2
goog| 1 | 3
Basically, I want to get identify the row count by symbol and then by dataset. I know that I can just grab "i" to get the rowcount for the dataset, but I'm having trouble pulling a symbol count
Thanks!
2022.04.06 10:18 AM
2022.04.06 10:18 AM
sums i=i by sym
did the trick
2022.04.07 02:50 AM
Not entirely clear what you’re looking for here. If you want to produce a 1…N list for each symbol you can use til
and avoid the sums and comparisons:
q)select 1+til count i by sym from t
sym | x
----| ---------------
aapl| 1 2 3 4 5
goog| 1 2 3 4 5 6 7 8
msft| 1 2 3 4 5 6 7
but it’s hard to see a use for the lists. Perhaps you simply want to count rows for each symbol?
q)exec count i by sym from t
aapl| 5
goog| 8
msft| 7
q)\ts:1000 select sums i=i by sym from t
4 10720
q)\ts:1000 exec count i by sym from t
1 9584
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.