2014-11-03 60 views
-2

我有类似的查看输出。sql多重连接,集合

V1与输入CE1

Costcode itemcode costcode 
CE1  ITEM1  CE2 
CE1  ITEM2  CE3 
CE1  ITEM3  -- 

当如果我再次执行V1与输入CE2

Costcode itemcode costcode 
CE2  ITEM4  CE4 
CE2  ITEM5  -- 
CE2  ITEM6  -- 

当如果我再次执行V1与输入CE4

Costcode itemcode costcode 
CE4  ITEM7  -- 
CE4  ITEM8  -- 

当再次如果我用输入CE3执行V1

Costcode itemcode costcode 
CE3  ITEM9  -- 
CE3  ITEM10  -- 

我怎样才能像

Costcode itemcode costcode 
CE1  ITEM1  CE2 
CE1  ITEM2  CE3 
CE2  ITEM4  CE4 

而且

Costcode itemcode costcode 
CE1  ITEM3  -- 
CE2  ITEM5  -- 
CE2  ITEM6  -- 
CE4  ITEM7  -- 
CE4  ITEM8  -- 
CE3  ITEM9  -- 
CE3  ITEM10  -- 

输出怎样才能在SQL或PLSQL这样的输出?以及如何执行视图V1多次获得像这样的输出与改变costcode的最后columna的条件。意思是我想要树直到最后一个costcode结束。

+6

请编辑您的问题,表明产生的各种结果集的代码。 – 2014-11-03 11:37:25

+3

从您提到的内容中很难理解 – 2014-11-03 11:38:44

+0

@Sandip因为您是新用户请参阅此链接首先http://stackoverflow.com/help&请提问有用的问题。不要问任何没有意义的问题。 – 2014-11-03 11:46:43

回答

0

查询1:

select costcode, itemcode, costcode from v1 where costcode is not null; 

查询2:

select costcode, itemcode, costcode from v1 where costcode is null;