试着查询从上个月倒数第二天到本月倒数第二天的数据,结果出错了,怎么改

解决方案 »

  1.   

    select rownum, t.*
      from (select to_char(SC_GROSSTIME, 'yyyy-mm-dd hh24:mi:ss'),
                   SC_TRACETIME,
                   sc_TruckNo,
                   sc_Qty db,
                   sc_NetQty,
                   sc_Qty,
                   sc_NetQty - sc_BatchQty jdwc,
                   decode(sc_Qty,
                          0,
                          null,
                          round((sc_NetQty - sc_Qty) / sc_Qty * 100, 3)) xdcl,
                   null yh,
                   null bz
              from sc_data.sc_Weighting_tb
              where  SC_SHIPTYPENO = 'ZA'  
            
              {and SC_PRODUCTNAME between LAST_DAY(to_date({#val_P_YEAR#}||'-'||{#val_P_MONTH#}||'-1'||' 18:00:00', 'yyyy-mm-dd hh24:mi:ss')-1)-1 
    and LAST_DAY(to_date({#val_P_YEAR#}||'-'||{#val_P_MONTH#}||'-1'||' 18:00:00', 'yyyy-mm-dd hh24:mi:ss')-1) }
              {  and SC_PRODUCTNAME ='#val_wl#' }) t
    union all
    select null,
           '合计',
           null,
           null,
           sum(db),
           sum(sc_NetQty),
           sum(sc_Qty),
           sum(jdwc),
           decode(sum(sc_Qty),
                  0,
                  null,
                  round(sum(jdwc) / sum(sc_Qty) * 100, 3)) xdcl,null,null
      from (select SC_GROSSTIME,
                   SC_TRACETIME,
                   sc_TruckNo,
                   sc_Qty db,
                   sc_NetQty,
                   sc_Qty,
                   sc_NetQty - sc_Qty jdwc,
                   decode(sc_Qty,
                          0,
                          null,
                          round((sc_NetQty - sc_Qty) / sc_Qty * 100, 3)) xdcl,
                   null yh,
                   null bz
              from sc_data.sc_Weighting_tb
              where  SC_SHIPTYPENO = 'ZA'  
            {and SC_PRODUCTNAME between LAST_DAY(to_date({#val_P_YEAR#}||'-'||{#val_P_MONTH#}||'-1'||' 18:00:00', 'yyyy-mm-dd hh24:mi:ss')-1)-1 and LAST_DAY(to_date({#val_P_YEAR#}||'-'||{#val_P_MONTH#}||'-1'||' 18:00:00', 'yyyy-mm-dd hh24:mi:ss')-1) }
              {  and SC_PRODUCTNAME ='#val_wl'# }) t