>  这个执行的结果是 successct,failct总有一个是0,两个不能共存

你的测试集是什么样的呢?理论上如果测试集是:

ip    | t | status
----------------
ip1 | 1 | success
ip1 | 2 | failed
ip1 | 3 | success
ip1 | 4 | failed

那么出来的结果应该是

ip | succss sum | failed sum
--------------------------------------
ip1| 4                |  6


如果总有一个是0,那可能的原因是源数据中同一个 ip key 的数据只有一条。

Best,
Jark

On Mon, 27 Apr 2020 at 09:37, Leonard Xu <xbjt...@gmail.com> wrote:

> Hi,
>
> FILTER是SQL标准里的语法,可以参考[1]
> FLINK SQL是支持该语法的,类似的例子官网文档可以参考 [2]中最后的例子
>
> Best,
> Leonard Xu
>
> [1] https://modern-sql.com/feature/filter <
> https://modern-sql.com/feature/filter>
> [2]
> https://ci.apache.org/projects/flink/flink-docs-master/zh/dev/table/tuning/streaming_aggregation_optimization.html
> <
> https://ci.apache.org/projects/flink/flink-docs-master/zh/dev/table/tuning/streaming_aggregation_optimization.html
> >
> > 在 2020年4月27日,05:51,王双利 <all...@163.com> 写道:
> >
> > 没找到 filter这个语法
> >
> >
> >
> > 王双利
> >
> > 发件人: Jark Wu
> > 发送时间: 2020-04-26 23:50
> > 收件人: user-zh
> > 主题: Re: sql 行转列
> > Hi
> >
> > 如果我理解的没错,agg with filter 语法能满足你的需求。
> >
> > select ip,
> >  sum(t) filter (where status = 'success')
> >  sum(t) filter (where status = 'fail')
> > from view1
> > group by ip
> >
> > Best,
> > Jark
> >
> > On Sun, 26 Apr 2020 at 20:56, Leonard Xu <xbjt...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >>> select ip,
> >>> case status when 'success' THEN sum(t) ELSE 0 end successct,
> >>> case status when 'fail' THEN sum(t) ELSE 0 end failct
> >>> from view1
> >>> group by ip
> >>
> >> 这个 sql 应该ok的,看讨论也可以满足你的需求,是有报错吗?麻烦贴下报错和 view1的大致逻辑
> >>
> >> Best,
> >> Leonard Xu
>
>

回复