ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 我写过的sql记录2

我写过的sql记录2

原创 Linux操作系统 作者:grubbyoo 时间:2008-08-29 14:32:55 0 删除 编辑

CREATE TABLE BOM (PARENT VARCHAR2(10),CHILD VARCHAR2(10),P_QTY NUMBER, C_QTY NUMBER);

INSERT INTO BOM VALUES ('A','B',1,3);
INSERT INTO BOM VALUES ('B','C',2,3);
INSERT INTO BOM VALUES ('C','D',5,6);
INSERT INTO BOM VALUES ('D','E',1,2);
INSERT INTO BOM VALUES ('A','Z',1,3);


我再加一个    B ,F,2,5
B由半成品C和原材料 F 组成

INSERT INTO BOM VALUES ('B','F',7,9);



select    child,
             power(10,sum(log(10,substr(con_qty,2+7*n-7,6)) )) num
from
   (            select             CHIlD ,     level m,
                                      sys_connect_by_path((TO_char(c_qty/P_QTY,'00.00')),'-') con_qty
                 from               bom
                 WHERE          CONNECT_BY_ISLEAF=1
                 start with      parent='A'
                 Connect By    Parent = PRIOR  CHIlD )                              a,
  (  select     rownum n  from     dual connect by rownum<10 ) b --这里限定 产品与原材料最多9层
where m >=n
group by child

select  decode(s_n+v_n,2,c_n||'.'||country_abbr,null) country_abbr ,
           decode(v_n,1,s_n||'.'||state_abbr,null) state_abbr ,
           v_n||'.'||villiage_abbr  villiage_abbr
from
(select     dense_rank() over  ( order by country_abbr)                                                                c_n, country_abbr ,
               dense_rank()  over  (partition by  country_abbr order by country_abbr,state_abbr)     s_n,     state_abbr   ,
               row_number() over  (partition by  country_abbr,state_abbr order by villiage_abbr)      v_n ,villiage_abbr
from
t_a
)

 

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9066649/viewspace-438912/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 本人写的sql记录
请登录后发表评论 登录
全部评论

注册时间:2008-08-29

  • 博文量
    11
  • 访问量
    23093