orcale实现自定义优先级排序的SQL

来源:互联网 发布:thinkphp3.2博客源码 编辑:程序博客网 时间:2024/05/16 08:46

作者:

orcale实现自定义优先级排序的SQL


select fchdno,
           bom_id,
           owner_id,
           customer_id,
           fcdate,
           period,
           fctrac,
           market,
           system_desc,
           crt_type,
           prod_model,
           prod_chassis,
           magnetic_field,
           mcu_code,
           f_pre_qty,
           f_qty,
           f_test_qty
    from (with a as (select fh.fchdno,
                            fh.bom_id,
                            fh.owner_id,
                            fh.customer_id,
                            to_char(fi.fcdate, 'YYYY-MM-DD') fcdate,
                            '' period,
                            fi.fctrac,
                            fh.market,
                            fh.system_desc,
                            fh.crt_type,
                            fh.prod_model,
                            fh.prod_chassis,
                            '' magnetic_field,
                            fh.mcu_code,
                            fi.f_pre_qty,
                            fi.f_qty,
                            fi.f_test_qty
                       from t_fcst_header fh, t_fcst_item fi
                      where fh.fchdno = fi.fchdno
                        and fh.prod_model || fh.prod_chassis =
                            (select distinct prod_model || item_chassis
                               from mid_som_item_master
                              where item = 'H3-32P60B1-AACB0AA')
                        and fh.customer_id = '301428'
                        and to_char(fi.fcdate, 'YYYY-MM-DD') <= '2012-12-30')
           select a.*, 1 seq
             from a
            where a.bom_id || a.owner_id || a.fcdate =
                  'H3-32P60B1-AACB0AA' || 'wunn' || '2012-12-30'
           UNION
           select a.*, 2 seq
             from a
            where a.bom_id || a.fcdate =
                  'H3-32P60B1-AACB0AA' || '2012-12-30'
              and a.owner_id != 'wunn'
           UNION
           select a.*, 3 seq
             from a
            where a.bom_id || a.owner_id = 'H3-32P60B1-AACB0AA' || 'wunn'
              and a.fcdate != '2012-12-30'
           UNION
           select a.*, 4 seq
             from a
            where a.fcdate || a.owner_id =
                  '2012-12-30' || 'wunn'
              and a.bom_id != 'H3-32P60B1-AACB0AA'
           UNION
           select a.*, 5 seq
             from a
            where a.owner_id != 'wunn'
              and a.bom_id != 'H3-32P60B1-AACB0AA'
              and a.fcdate != '2012-12-30')
            order by seq

原创粉丝点击