Suppose I have a table, which looks like the following:
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
Whenever there are 2 same consecutive IP
s, the InventoryVAS
columns will always have same value except for last character.
e.g. fvas in fvas1 and fvas2 for 172.21.4.97
I need my final table to be like this:
InventoryVAS colVAS IP
fvas 5/6 172.21.4.97
abcd 4 10.4.6.89
ef 7/8 169.21.5.67
In real scenario, my table has 100s of records which have same IP
s and InventoryVAS
value same for that IP
except the last character. I need to exclude this last character so as to make it a single row with middle column (colVAS) value = (value in row1)/(value in row2).
I've tried Gordon's answer and got the following:
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