select router_name, year(report_date) as c_year ,  sum_money ,month(report_date) as c_month ,  qty ,unit_price,partname  from V_production_stat  WHERE 
jobno = 'JOH-GC-0406-0354' and  isnull(long_count,0)=0 
--(3 row(s) affected)select router_name, year(report_date) as c_year ,  sum_money ,month(report_date) as c_month ,long_count as qty ,unit_price,partname  from V_production_stat  WHERE 
jobno = 'JOH-GC-0406-0354' and  isnull(long_count,0)<>0 
-------(17 row(s) affected)我把这二个表union后只有19条记录,晕倒呀
(19 row(s) affected)

解决方案 »

  1.   

    select router_name, year(report_date) as c_year ,  sum_money ,month(report_date) as c_month ,  qty ,unit_price,partname  from V_production_stat  WHERE 
    jobno = 'JOH-GC-0406-0354' and  isnull(long_count,0)=0 
    union all
    select router_name, year(report_date) as c_year ,  sum_money ,month(report_date) as c_month ,long_count as qty ,unit_price,partname  from V_production_stat  WHERE 
    jobno = 'JOH-GC-0406-0354' and  isnull(long_count,0)<>0 --union会过滤相同的记录,union all不会
      

  2.   

    union:过滤重复数据
    union all :忽略重复~
      

  3.   

    Union 会合并相同的行!可用 Union All