SQL创建TABLE

来源:互联网 发布:在c语言中随机数函数是 编辑:程序博客网 时间:2024/05/22 08:22
create or replace view zeltv_warehouse_h
(warehouse_io_id, tm_warehouse_id, ware_name, product_info_id, product_no, prdt_size_gp, k3_product_id, color_id, size_group, stock_now, create_date, reference_no, ref_type, chal_type, brand)
as
select st.sc_tt_warehouse_io_id,
       w.ware_id,
       w.ware_name,
       st.sc_tm_product_info_id,
       p.product_no,
       a.attribute_value,
       p.k3_product_id,
       p.color_id,
       p.product_size,
       st.stock_now_after,
       st.io_create_date,
       decode(d.dealer_no,null,s.store_no,nvl(substr(d.dealer_no,1,instr(d.dealer_no,'-')-1),d.dealer_no)) reference_no,
       decode(d.dealer_no,null,'S','C') ref_type,
       decode(d.dealer_no,null,s.channel_type,d.channel_type) chal_type,
       decode(d.brand,null,s.brand,d.brand) brand
  from (select t.sc_tt_warehouse_io_id,
               sc_tm_warehouse_id,
               sc_tm_product_info_id,
               stock_now_after,
               to_char(t.io_create_date, 'yyyymmdd') io_create_date,
               rank() over(partition by sc_tm_warehouse_id, sc_tm_product_info_id order by io_create_date desc, io_expire_date desc, sc_tt_warehouse_io_id desc) mm
          from sc_tt_warehouse_io t
         where to_char(t.io_create_date, 'yyyymmdd') =
               to_char(last_day(t.io_create_date), 'yyyymmdd')
           and mark_for_delete = '0'
           and to_char(t.io_create_date, 'yyyymmdd') >=  '2013-01-01'
              --and sc_tm_product_info_id = 91589
           --and sc_tm_warehouse_id = 1020239
           ) st
  left join sc_tm_product_info p
    on st.sc_tm_product_info_id = p.sc_tm_product_info_id
  LEFT JOIN sc_tm_product_attribute A
    ON sT.SC_TM_PRODUCT_INFO_ID = A.SC_TM_PRODUCT_INFO_ID
   AND A.ATTRIBUTE_ID = 'MAP_KEY_PRDT_SIZE_GP'
   left join sc_tm_warehouse w
   on w.sc_tm_warehouse_id = st.sc_tm_warehouse_id
   left join sc_tm_dealer_info d
   on w.sc_tm_dealer_info_id = d.sc_tm_dealer_info_id
   left join sc_tm_store_info s
   on s.sc_tm_store_info_id = w.sc_tm_store_info_id
 where mm = 1;
0 0
原创粉丝点击