【问题标题】:multiple count(substring) with windowing psql 8.4.4具有窗口 psql 8.4.4 的多个计数(子字符串)
【发布时间】:2010-06-24 14:57:11
【问题描述】:

我正在尝试创建以下视图,但出现以下错误: 我能够执行 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)

【问题讨论】:

  • 你能提供一些样本数据(带有假地址)吗?不知道你为什么需要这个窗口 - 一个小组可以工作吗?

标签: postgresql windowing


【解决方案1】:

找到一个可行的解决方案:

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';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多