In KSQL, How to select max window record after windowing and group by?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 04:47:39

问题


ksql> CREATE TABLE HOPPING_TABLE AS SELECT ID, WINDOWSTART() AS WINSTART, COUNT(*) AS CNT FROM MY_STREAM HOPPING WINDOW (SIZE 30 DAYS, ADVANCED BY 1 DAYS) GROUP BY ID;

ksql> SELECT ID, WINSTART, CNT FROM HOPPING_TABLE;

id                    winstart        cnt
-------------------------------------------

874163197805291909    1547164800000    23
874163197805291909    1547424000000    11
874163197805291909    1547510400000    26
874163197805291909    1547683200000    12

660071199310134801    1545868800000    6
660071199310134801    1546560000000    7
660071199310134801    1547251200000    3

Now, I just care about the cnt of window with max winstart value for each ID grouped, how to achieve that by KSQL then? Considering above example (2 IDs grouped), I hope a table can be generated from above HOPPING TABLE with the following records:

id                    winstart        cnt
-------------------------------------------

874163197805291909    1547683200000    12

660071199310134801    1547251200000    3

来源:https://stackoverflow.com/questions/54232400/in-ksql-how-to-select-max-window-record-after-windowing-and-group-by

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!