开发者

Postgresql count substring with a "where" clause

开发者 https://www.devze.com 2023-01-05 12:11 出处:网络
I am trying to count a substring, while matching different values from another column. The following statement gives me a syntax error on the where clause.

I am trying to count a substring, while matching different values from another column. The following statement gives me a syntax error on the where clause.

Is the following even possible开发者_运维知识库, and what is the correct syntax?

select address,
       datacenter,
       ifdesc,
       count(substring(ifdesc, 'Ethernet0/*') where ifadminstatus = '1' and ifoperstatus = '1')  over (partition by address) mod0_uu,
       count(substring(ifdesc, 'Ethernet0/*') where ifadminstatus = '2') over (partition by address) mod0_ad
  from ifstatus;


Something like this?

select address,
       datacenter,
       ifdesc,
       count(case when ifadminstatus = '1' and ifoperstatus = '1' then substring(ifdesc, 'Ethernet0/*') else null end )  over (partition by address) mod0_uu,
       count(case when ifadminstatus = '2' then substring(ifdesc, 'Ethernet0/*') else null end ) over (partition by address) mod0_ad
  from ifstatus  WHERE ifadminstatus in ('1','2');
0

精彩评论

暂无评论...
验证码 换一张
取 消