兑现昨晚的说法,公布自己瞎弄的sql,算是歪打正着吧。看看这个sql,你要觉得怪异,尽管说:
1)
select dy.jh, dy.jm, dy.lze as dylze, coalesce(ls.lze,0.00) as lslze, coalesce(dy.lze,0.00)+coalesce(ls.lze,0.00) as lze from
  (select d.jh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.pdssk) as pdlze, sum(c.zdssk) as zdlze,
   sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_bkml as b
where c.yxn=2008
   and c.jyr>='20070701' and c.jyr<='20080701'
   and c.bkdh='33-2' and c.dyfw='本地' and c.dylx!='零售'
   and b.nd=2008 and b.bkdh='33-2'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as dy,

  (select d.jh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.pdssk) as pdlze, sum(c.zdssk) as zdlze,
     sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_bkml as b
where c.yxn=2008
   and c.jyr>='20070701' and c.jyr<='20080701'
   and c.bkdh='33-2' and c.dyfw='本地' and c.dylx='零售'
   and b.nd=2008 and b.bkdh='33-2'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as ls
where dy.jh=ls.jh;

2)
select dy.dqh, sum(coalesce(dy.lze,0.00)) as dylze, sum(coalesce(ls.lze,0.00)) as lslze, sum(coalesce(dy.lze,0.00)+coalesce(ls.lze,0.00)) as lze from
  (select d.jh, d.dqh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_tjlx as t
where c.yxn=2008
   and c.bkdh = t.bkdh
   and c.jyr>='20071201' and c.jyr<='20071210'
   and c.clbz!='变动' and c.dyfw='本地' and c.dylx!='零售'
   and t.nd=2008 and t.bkfl='畅销及潜力'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as dy,

  (select d.jh, d.dqh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_tjlx as t
where c.yxn=2008
   and c.bkdh = t.bkdh
   and c.jyr>='20071201' and c.jyr<='20071210'
   and c.clbz!='变动' and c.dyfw='本地' and c.dylx='零售'
   and t.nd=2008 and t.bkfl='畅销及潜力'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as ls
where dy.jh=ls.jh
group by dy.dqh
order by dy.dqh;