带窗口的多重计数(子字符串) psql 8.4.4

发布于 2024-09-06 21:02:35 字数 771 浏览 3 评论 0原文

我正在尝试创建以下视图,但出现以下错误: 我可以执行 1 个计数语句(如果删除 AS“Mod0”)是否可以对多个子字符串进行计数,并将输出计数到新列?

create view portcnt as 
    select 
    address,
    datacenter,
    ifdesc,
    count(substring(ifdesc, 'Ethernet0/*')) as "Mod0",
    count(substring(ifdesc, 'Ethernet1/*')) as "Mod1",
    count(substring(ifdesc, 'Ethernet2/*')) as "Mod2",
    count(substring(ifdesc, 'Ethernet3/*')) as "Mod3",
    count(substring(ifdesc, 'Ethernet4/*')) as "Mod4",
    count(substring(ifdesc, 'Ethernet5/*')) as "Mod5",
    count(substring(ifdesc, 'Ethernet6/*')) as "Mod6"
    over (partition by address)
    from ifstatus where datacenter = 'DC' 
    and ifadminstatus = '1' and ifoperstatus = '1';
ERROR:  syntax error at or near "by"
LINE 13:  over (partition by address)

I am trying to create the following view, and I get the error below:
I am able to do 1 count statement (if I remove the AS "Mod0") Is it possible to count multiple substrings, with the output count to a new column?

create view portcnt as 
    select 
    address,
    datacenter,
    ifdesc,
    count(substring(ifdesc, 'Ethernet0/*')) as "Mod0",
    count(substring(ifdesc, 'Ethernet1/*')) as "Mod1",
    count(substring(ifdesc, 'Ethernet2/*')) as "Mod2",
    count(substring(ifdesc, 'Ethernet3/*')) as "Mod3",
    count(substring(ifdesc, 'Ethernet4/*')) as "Mod4",
    count(substring(ifdesc, 'Ethernet5/*')) as "Mod5",
    count(substring(ifdesc, 'Ethernet6/*')) as "Mod6"
    over (partition by address)
    from ifstatus where datacenter = 'DC' 
    and ifadminstatus = '1' and ifoperstatus = '1';
ERROR:  syntax error at or near "by"
LINE 13:  over (partition by address)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱本泡沫多脆弱 2024-09-13 21:02:35

找到了一个有效的解决方案:

create view portcnt1 as
    select
    address,
    datacenter,
    ifdesc,
    count(substring(ifdesc, 'Ethernet0/*')) 
    over (partition by address) mod0,
    count(substring(ifdesc, 'Ethernet1/*'))
    over (partition by address) mod1,
    count(substring(ifdesc, 'Ethernet2/*'))
    over (partition by address) mod2,
    count(substring(ifdesc, 'Ethernet3/*'))
    over (partition by address) mod3,
    count(substring(ifdesc, 'Ethernet4/*'))
    over (partition by address) mod4,
    count(substring(ifdesc, 'Ethernet5/*'))
    over (partition by address) mod5,
    count(substring(ifdesc, 'Ethernet6/*'))
    over (partition by address) mod6,
    count(substring(ifdesc, 'Ethernet7/*'))
    over (partition by address) mod7,
    count(substring(ifdesc, 'Ethernet8/*'))
    over (partition by address) mod8,
    count(substring(ifdesc, 'Ethernet9/*'))
    over (partition by address) mod9
    from ifstatus
    where ifadminstatus = '1' and ifoperstatus = '1';

found a solution that worked:

create view portcnt1 as
    select
    address,
    datacenter,
    ifdesc,
    count(substring(ifdesc, 'Ethernet0/*')) 
    over (partition by address) mod0,
    count(substring(ifdesc, 'Ethernet1/*'))
    over (partition by address) mod1,
    count(substring(ifdesc, 'Ethernet2/*'))
    over (partition by address) mod2,
    count(substring(ifdesc, 'Ethernet3/*'))
    over (partition by address) mod3,
    count(substring(ifdesc, 'Ethernet4/*'))
    over (partition by address) mod4,
    count(substring(ifdesc, 'Ethernet5/*'))
    over (partition by address) mod5,
    count(substring(ifdesc, 'Ethernet6/*'))
    over (partition by address) mod6,
    count(substring(ifdesc, 'Ethernet7/*'))
    over (partition by address) mod7,
    count(substring(ifdesc, 'Ethernet8/*'))
    over (partition by address) mod8,
    count(substring(ifdesc, 'Ethernet9/*'))
    over (partition by address) mod9
    from ifstatus
    where ifadminstatus = '1' and ifoperstatus = '1';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文