当前位置: 代码迷 >> Oracle开发 >> Oracle SQL 求指点
  详细解决方案

Oracle SQL 求指点

热度:86   发布时间:2016-04-24 06:39:34.0
Oracle SQL 求指导
select 
        distinct p.userdefined2 as fld_TMD_order_no,
        ps.wmps_traceID as fld_TMD_connote_no,
        sum(NVL(os.userdefined2,0)* os.wmos_qtypicked) as fld_TOL_price,
        --sum(NVL(os.userdefined2,0)* os.wmos_qtypicked)   as fld_TOL_total_amount,
       -- replace(to_char(wmsys.wm_concat(rtrim(ws.userdefined5))),',',';') as fld_edi_description,
        
        ws.userdefined5 as fld_edi_description,
        TO_CHAR(SYSDATE,'yyyymmdd') as fld_TM_manifest_id,
        1 as fld_TM_cartons ,
        nvl(ps.wmps_grossweight,0)as fld_TM_cbm ,
        nvl(ps.wmps_cubic,0)as fld_TM_weight ,
        'AIR'as  fld_TM_container_type,
         '' as fld_TM_container_no,
         'AUD' as fld_TM_seal_no,
         ''as fld_TM_vessel_name,
         TO_CHAR(SYSDATE+1,'DD/MM/YYYY') as fld_TM_edt,  
        1 as fld_TMD_cartons,
        nvl(ps.wmps_cubic, 0) as fld_TMD_cbm,
        nvl(ps.wmps_grossweight, 0) as fld_TMD_weight,
        to_char(sysdate,'Month dd yyyy hh:miAM','NLS_DATE_LANGUAGE = American')||'_BWB_Manifest' as fld_TO_filename,
        TO_CHAR(SYSDATE+3,'dd/mm/yyyy') as fld_TO_import_date,
        o.wmor_soreference2 as fld_TO_order_no,
        1 as fld_TO_carrier,
        o.wmor_consigneename as fld_TO_surname,
        NVL(o.wmor_c_address1, ' ') as fld_TO_address_1,
        NVL(o.wmor_c_address2, ' ') as fld_TO_address_2,
        o.wmor_c_country as fld_TO_country_code,
        o.wmor_c_city as fld_TO_suburb,
        NVL(o.wmor_c_province, ' ') as fld_TO_state,
        o.wmor_c_zip as fld_TO_postcode,
        NVL(o.wmor_c_tel1, ' ') as fld_TO_telephone,
         'AeParcelPac' as fld_TO_delivery_instr,
         NVL(o.wmor_c_address3, ' ') as fld_TO_address_3,
         NVL(ps.wmps_grossweight, 0) as fld_TO_weight,
         1 as fld_TOL_line_no,
         '' as fld_TOL_product_no,
         '' as fld_TOL_item_no,   
         1 as fld_TOL_quantity,  
        TO_CHAR(SYSDATE+5,'DD/MM/YY') as fld_TOL_promised_date,   

         ws.userdefined5 as fld_edi_description,
         'Jeanswest' as mame,
         '11th Floor, Unit C, 2 Tins Centre'as addr1,
         'Hung Cheung Road 3' as addr2,
         'Tuen Mun' as city,
         'Hong Kong' as state,
         'NA' as postcode,
         'HK'as country

from wm_out_packing_summary ps,wm_out_packing p,wm_out_order o,wm_out_order_sku os,cd_wh_sku ws
where 
     ps.wmps_traceid=p.wmop_traceid
and  p.wmop_orderno=o.wmor_order_no
and  p.wmop_sku_code=os.wmos_sku_code
and  os.wmos_order_no=o.wmor_order_no
and  ws.cdsk_sku_code=os.wmos_sku_code
group by ps.wmps_traceID,o.wmor_soreference2,o.wmor_consigneename,o.wmor_c_country,o.wmor_c_city,o.wmor_c_zip,ws.userdefined5,ps.wmps_grossweight,
ps.wmps_cubic,ps.wmps_cubic,ps.wmps_grossweight,o.wmor_c_address1,o.wmor_c_address2,o.wmor_c_province,o.wmor_c_tel1,o.wmor_c_address3,ps.wmps_grossweight, p.userdefined2;

 
这个是我写的Sql语句,有点乱。。 查询出来后的结果是如图



现在要以wmps_traceID 为主唯一查询,不要出现重复,然后要把价格累加。 还有一个 ws.userdefined5 字段里面有描述,要把 ws.userdefined5这个字段 不同的内容用 , 放一起显示出来,还不能重复。 
  相关解决方案