具有多个键列的数据透视表

时间:2019-07-25 06:02:55

标签: kdb

我有下表:

Map<String, String>
    events = result.getEvents()
                   .stream()
                   .map(s -> new SimpleEntry<>(s.getReferenceID(),s.getData().stream().map(Data::getValue).filter(StringUtils::isNotEmpty).collect(Collectors.joining("-"))))
                   .collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue));

我想将t:(([]y:2001 2002) cross ([]m:5 6 7) cross ([]sector:`running`hiking`swimming`cycling)),'([]sales: 14 12 5 9 4 894 1 4 87 12 24 6 4 8 64 354 3 4 86 43 1053 2 43 4); y m sector sales ------------------------ 2001 5 running 14 2001 5 hiking 12 2001 5 swimming 5 2001 5 cycling 9 2001 6 running 4 2001 6 hiking 894 2001 6 swimming 1 2001 6 cycling 4 ... 2002 5 running 4 2002 5 hiking 8 2002 5 swimming 64 2002 5 cycling 354 2002 6 running 3 ... 的值旋转sales,同时保留前两个sectory列,以使结果表如下所示:< / p>

m

1 个答案:

答案 0 :(得分:2)

按照 https://code.kx.com/v2/kb/pivoting-tables/

q) P:asc exec distinct sector from t;
q) exec P#(sector!sales) by y:y,m:m from t

如果需要普通表,可以通过() xkey取消键的结果。