NULL值导致的排序异常

一、NULL值导致的排序异常

如果begintime,有null值,那么排序是会有问题,结果会将begintime为空的明细放在报表最前面显示

set v_sql=v_sql||' a4 as (select indcode,begintime,rownumber() over(order by ' || v_orderTag ||') as tag4 from session.rst where tag=4),';
  

set v_sql='insert into SESSION.rst(indcode,begintime)'
  || 'with ' || v_sql || ' a as (select * from SESSION.rst)'
  || ' select  a.indcode,a.begintime from a '
  || 'left join a4 on  a.indcode=a4.indcode and coalesce(a.begintime,''2000-01-01'')=coalesce(a4.begintime,''2000-01-01'')' else '' end  

 

二、NULL值导致的计算结果异常

如果sql语句将price字段为查询条件,如果这个字段值为null,那么查询结果中该字段对应的值将不会被计入结果集中。

insert into session.temp(citycode,cityname,tradecode,tradename,sell,tq_sell,sq_sell)
  SELECT c.provcode as citycode,c.provname as cityname,b.tradecode,b.tradename,
       sum(sell_amount) AS sell

          FROM  a , b ,c
         WHERE d_day in(v_beginyearmonth,v_endyearmonth)
                     AND a.c_brand=b.tobacode

                    and a.i_org=c.compcode
                    and b.price<260

                    GROUP BY b.tradecode,b.tradename,c.provcode,c.provname;

你可能感兴趣的:(DB2)