当前输出:
PORT BANDWIDTH TYPE
XE-5/1/0 29267 XE
XE-5/1/0 48154 XE
GE-4/0/0 443 GE
XE-3/0/0 28077 XE
GE-1/0/0 1032 GE
GE-1/0/6 2285 GE
XE-5/1/0 XE
查询:
select *
from (select d.port,d.bandwidth from dummy123 d where d.bandwidth is not null)
pivot (sum(bandwidth) as totalbandwidth for port in ( 'GE%' ,'XE%'))
使用pivot时有没有办法使用like或%运算符?
答案 0 :(得分:1)
不,你不能。但您可以使用substr截断字符串。例如。尝试以下方法:
select *
from (select substr(d.port,1,2) portmask,
d.bandwidth
from dummy123 d where d.bandwidth is not null)
pivot (sum(bandwidth) as totalbandwidth for portmask in ( 'GE' ,'XE'))