logo 西林@生存 - 骑猪闯天下!
写了一超级变态的SQL查询
2006-10-28 16:12:00 By:xling

成品尾阶用料查询,还要查出最近采购单价和最低采购单价,还要查指定日期(默认为当天)的采购币别对应的海关汇率。这个工作量,简直难以言欲。而且报表工具还不具被写过程(可以在过程里写变量)的能力,只能写SELECT语句,我又不想写VIEW。。。

耗了今天一天的时间,最让我难以忍受不了的是网络那个叫卡,写程序都是远程登陆到服务器上进行,MD对服务器的ping值忽高忽低,害得我只好慢慢敲键盘。

发现:SYS_CONNECT_BY_PATH原来是不被Oracle9i以下的版本所支持的,下面代码里对尾阶的取法有点牵强,还得想办法把这个给取代掉。

汗...我都不想数用了几层子查询了。。

/* Formatted on 2006/10/28 16:24 (Formatter Plus v4.8.7) */
SELECT b.component_part_no, b.per_qty, b.attrition_rate, b.desp, b.comp_no,
       b.part_desp, b.width, b.weight, b.source_code, b.basic_unit_code,
       b.curr_code, b.nearest_price, b.min_price, b.exch_rate,
         b.per_qty
       * (1 + b.attrition_rate)
       * b.exch_rate
       * b.nearest_price AS ntd_amt_nearest,
         b.per_qty
       * (1 + b.attrition_rate)
       * b.exch_rate
       * b.min_price AS ntd_amt_min
  FROM (SELECT   a.*, asp_part.desp AS part_desp, asp_part.width,
                 asp_part.weight, asp_part.source_code,
                 asp_part.basic_unit_code,
                 jd_pkg_curr_price_exch.f_get_nearest_curr
                                           (a.component_part_no,
                                            a.comp_no
                                           ) AS curr_code,
                 jd_pkg_curr_price_exch.f_get_nearest_price
                                       (a.component_part_no,
                                        a.comp_no
                                       ) AS nearest_price,
                 jd_pkg_curr_price_exch.f_get_min_price
                                           (a.component_part_no,
                                            a.comp_no
                                           ) AS min_price,
                 jd_pkg_curr_price_exch.f_get_exch_by_date
                    (a.comp_no,
                     (jd_pkg_curr_price_exch.f_get_nearest_curr
                                                         (a.component_part_no,
                                                          a.comp_no
                                                         )
                     ),
                     SYSDATE
                    ) AS exch_rate
            FROM (SELECT   component_part_no, SUM (per_qty) AS per_qty,
                           NVL (attrition_rate, 0) AS attrition_rate, desp,
                           comp_no
                      FROM (SELECT     parent_part_no, component_part_no,
                                       item_no, per_qty, attrition_rate, desp,
                                       effective_date, closed_date, comp_no
                                  FROM asp_bom
                                 WHERE SYSDATE BETWEEN effective_date
                                                   AND closed_date
                                   AND comp_no = 'JD0201'
                            CONNECT BY PRIOR component_part_no =
                                                                parent_part_no
                            START WITH parent_part_no = '5201-3220101011')
                     WHERE component_part_no LIKE '1%'
                  GROUP BY component_part_no, attrition_rate, desp, comp_no) a,
                 asp_part
           WHERE a.comp_no = asp_part.comp_no(+) AND a.component_part_no = asp_part.code(+)
        ORDER BY a.component_part_no) b

转我的贴,写你的名,是一种可耻的行为!请不要让我BS你!
阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:

    密码:
    主页:
    标题:
    页面数据正在载入...
<<  < 2006 - 10 >  >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Placard
1,長江後浪推前浪,前浪死在沙灘上!
2,有了钱的男人,才是真正的男人...
3,不要以为把你的小JJ埋进土里,你就rape了整个地球;不要以为把你的小JJ朝向天空,你就rape了整个宇宙!
Logon System
Search
Info about this blog
Others
myDream
bxna 京ICP备05002321号