假设我有一个表格,如下所示:
InventoryVAS colVAS IP
fvas1 5 172.21.4.97
fvas2 6 172.21.4.97
abcd 4 10.4.6.89
ef1 7 169.21.5.67
ef2 8 169.21.5.67
每当有 2 个相同的连续IP
s 时,InventoryVAS
除最后一个字符外,列将始终具有相同的值。
例如 fvas1 和 fvas2 中的 fvas 用于 172.21.4.97
我需要我的决赛桌是这样的:
InventoryVAS colVAS IP
fvas 5/6 172.21.4.97
abcd 4 10.4.6.89
ef 7/8 169.21.5.67
在实际场景中,我的表有 100 条记录,除了最后一个字符外,它们IP
的 s 和InventoryVAS
值相同。IP
我需要排除最后一个字符,以使其成为具有中间列(colVAS)值=(row1中的值)/(row2中的值)的单行。
我试过戈登的回答并得到以下信息:
create table VAS(
InventoryVAS varchar2(40),
colVAS number,
IP varchar2(40)
)
insert into VASInventory values ('fvas1',5,172.21.4.97);
insert into VASInventory values ('fvas2',6,172.21.4.97);
insert into VASInventory values ('abcd',4,10.4.6.89);
insert into VASInventory values ('ef1',7,169.21.5.67);
insert into VASInventory values ('ef2',8,169.21.5.67);
select * from VAS;
select substr(InventoryVas, length(InventoryVas) - 1) as InventoryVas,
(case when min(colvas) <> max(colvas) then min(colVas)||'/'||max(colVas)
else min(colvas)
end) as colVas,
ip
from VAS
group by substr(InventoryVas, length(InventoryVas) - 1), ip;
---------------------------------------------------------------------------
ERROR :
ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Error at Line: 24 Column: 19
create table VAS(
InventoryVAS varchar2(40),
colVAS number,
IP varchar2(40)
)
drop table VAS;
insert into VASInventory values ('fvas1',5,172.21.4.97);
insert into VASInventory values ('fvas2',6,172.21.4.97);
insert into VASInventory values ('abcd',4,10.4.6.89);
insert into VASInventory values ('ef1',7,169.21.5.67);
insert into VASInventory values ('ef2',8,169.21.5.67);
select * from VAS;
select substr(InventoryVas, length(InventoryVas) - 1) as InventoryVas,
(case when min(colvas) <> max(colvas) then min(colVas)||'/'||max(colVas)
else min(colvas)
end) as colVas,
ip
from VAS
group by substr(InventoryVas, length(InventoryVas) - 1), ip;
---------------------------------------------------------------------------
ERROR :
ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Error at Line: 24 Column: 19