Hi Guoqin, I think you could use the Window Top-N. There's a recipe in the Flink SQL Cookbook [1]. The example uses a SUM which you should change to MAX and of course you change the rownum to 1 instead of 3.
Best regards, Martijn [1] https://github.com/ververica/flink-sql-cookbook/blob/main/aggregations-and-analytics/11_window_top_n/11_window_top_n.md Op wo 8 dec. 2021 om 19:54 schreef Guoqin Zheng <lanson.zh...@gmail.com> > Hi Flink Community, > > I am curious what the recommended way is to select the event with a max > attribute value with SQL api. > > For example, I have an event stream like: > > { > deviceId, > locationId > gauge, > readtime, <-- eventTime > } > > I want to figure out which device and location has the max gauge over a > 5-mins window. > > Any advice would be greatly appreciated! > > Thanks! > -Guoqin > -- Martijn Visser | Product Manager mart...@ververica.com <https://www.ververica.com/> Follow us @VervericaData -- Join Flink Forward <https://flink-forward.org/> - The Apache Flink Conference Stream Processing | Event Driven | Real Time