2014-01-07 23:16:39
ÔÒò·ÖÎö: ±¾ÆÚµÄ´æ»õÃ÷ϸÕËÊÕÈë½ð¶î¡¢·¢³ö½ð¶îÓë×ÜÕ˽跽¡¢´û·½¶ÔÕ˲»Æ½£¬µ÷²¦ÒµÎñÖÆµ¥Ã»ÓÐÉèÖÃÖÐ¼ä¿ÆÄ¿£»Ó¦¸¶Ä£¿éʹÓÃ¿â´æÉÌÆ·ÖƵ¥¡£
½â¾ö·½°¸:
¨C´æ»õÓë×ÜÕ˶ÔÕËϵͳ²éѯÌõ¼þ
¨C1.1 ´æ»õºËËã²éѯÌõ¼þ£º²éѯ»á¼ÆÆÚ¼ä¡¢ÒÑÖÆÆ¾Ö¤µÄÃ÷ϸ¿ÆÄ¿¼´£¨cpzid is not null£©
¨C2.2 ×ÜÕ˲éѯÌõ¼þ£º²éѯ»á¼ÆÆÚ¼ä¡¢Íⲿƾ֤ϵͳΪia¡¢µÄδ×÷·Ï£¨iflag is null£©¼ÇÕË£¨ibook=1£©
¨C¿ª·¢»Ö¸´½Å±¾
select * from (select md,mc,coutno_id,ino_id from dbo.GL_accvouch where ccode=¡¯1406¡ä and iperiod=5) B
left join(select sum(iainprice) as iainprice,sum(iaoutprice)as iaoutprice,cpzid from ia_subsidiary where imonth=5 and cpzid is not null
group by cpzid ) A
on A.cpzid=B.coutno_id
where isnull(A.iainprice,0)<>md or isnull(A.iaoutprice,0)<>mc
order by coutno_id
¨C´æ»õºËËãÓë×ÜÕ˶ÔÕ˲»Æ½×ܽá
¨C²éѯ´æ»õÃ÷ϸ³öÈë¿âºÏ¼ÆÓëÆ¾Ö¤Ã÷ϸ½è´û·½ºÏ¼Æ(¿¼Âǵ½¶ÔÕË¿ÆÄ¿´«µ½×ÜÕËµÄÆ¾Ö¤¿ÉÄÜ´ÓÆäËûÄ£¿é£¨È磺ӦÊÕ/¸¶Ä£¿é¡¢×ÜÕË£©Éú³É£¬¹ÊÐè´ÓÁ½²½¿¼ÂÇ)
select sum(iAInPrice) as [ÊÕÈë½ð¶îºÏ¼Æ],sum(iAOutPrice) as [·¢³ö½ð¶îºÏ¼Æ] from ia_subsidiary where imonth=5 and cinvhead=¡¯1406¡ä and not cPZID is null ¡ª ºËËãºÏ¼Æ
select sum(md) as [ºËËã½è·½ºÏ¼Æ],sum(mc) as [ºËËã´û·½ºÏ¼Æ] from gl_accvouch where iperiod=5 and ccode=¡¯1406¡ä and coutsysname=¡¯ia¡¯ and ibook = 1 and iflag is null ¡ª ÓɺËËãÖÆµ¥µÄ×ÜÕ˺ϼÆ
select sum(md) as [×ÜÕ˽跽],sum(mc) as [×ÜÕË´û·½] from gl_accvouch where iperiod=5 and ccode=¡¯1406¡ä and ibook = 1 and iflag is null ¨C×ÜÕ˺ϼÆ
¨C˵Ã÷Ò»£º¼ÙÈç¡°ºËËãºÏ¼Æ¡±=¡°ÓɺËËãÖÆµ¥µÄ×ÜÕ˺ϼơ±£¬¶ø<>¡°×ÜÕ˺ϼơ±Ôò˵Ã÷ÓÐÍⲿģ¿éʹÓá®1406¡¯ÖÆÆ¾Ö¤£¬¿ÉÒÔͨ¹ýÏÂÃæ½Å±¾
select coutsysname as [Íⲿϵͳģ¿é],coutno_id as [ƾ֤Ë÷ÒýºÅ],ioutperiod as [Íⲿƾ֤ÆÚ¼ä],iperiod as [×ÜÕËÆÚ¼ä],ino_id as [ƾ֤ºÅ],cdigest,ccode,md,mc,ccode_equal from gl_accvouch where coutsysname is null and ccode=¡¯1406¡ä and ibook = 1 and iflag is null ¨C²»ÊǺËËãÉú³ÉµÄƾ֤
select coutsysname,coutno_id,md,mc,* from gl_accvouch where iperiod=5 and ccode=¡¯1406¡ä and ibook = 1 and iflag is null order by coutsysname ¨C²éѯƾ֤À´Ô´
¨CÈç²éѯ³ö1406ÓÐÓ¦¸¶Éú³É£¬ÔòÐ轫ÏÂÃæ²éѯ³öµÄ½è·½/´û·½ºÏ¼Æ·ÅÔÚ¡°ºËËãºÏ¼Æ¡±¶ÔÓ¦½Å±¾µÄ½è·½»õ·½£¬²é¿´Ëã³öµÄÖµÊÇ·ñÓë¡°×ÜÕ˺ϼơ±Ò»Ö£¨Èç²»Ò»Ö£¬ËµÃ÷ÎÒµÄÀíÂÛÓÐÎÊÌ⡣Ŀǰ»¹Î´·¢ÏÖ£©
select sum(md),sum(mc) from gl_accvouch where iperiod=5 and ccode=¡¯1405¡ä and coutsysname=¡¯ap¡¯ and ibook = 1 and iflag is null ¨CÓ¦¸¶ÖƵ¥½è´û·½ºÏ¼Æ
¨C˵Ã÷¶þ£º¼ÙÈç¡°ºËËãºÏ¼Æ¡±<>¡°ÓɺËËãÖÆµ¥µÄ×ÜÕ˺ϼơ±£¬Ôò˵Ã÷´æ»õºËËãÖÆµ¥·Ö¼¼´í£¨Èçµ÷²¦ÒµÎñ£©¡¢»òÕ߯¾Ö¤½ð¶îÊÖ¹¤ÐÞ¸Ä
¨C´ËʱÐèÒª±È½Ï½è·½¡¢´û·½ÎªÊ²Ã´²»¶Ô£¬¿ÉÒÔͨ¹ýÒÔϱ¿×¾µÄ·½Ê½²éѯ
¨C2.1 ²éѯ´æ»õÃ÷ϸÊÕÈë½ð¶î¸³Óè±ía ×ÜÕËÃ÷ϸ±í½è·½½ð¶î¼Ç¼¸³Óè±íb
select sum(iAInPrice) as iAInPrice,cpzid into a from ia_subsidiary where imonth=5 and cinvhead=¡¯1406¡ä and not cPZID is null and not iainprice is null group by cpzid
select ino_id,sum(md) as md,coutno_id into b from gl_accvouch where iperiod=5 and ccode=¡¯1406¡ä and coutsysname=¡¯ia¡¯ and ibook = 1 and iflag is null and md<>0 group by ino_id,coutno_id
¨C2.2 ²éѯ´æ»õÃ÷ϸ·¢³ö½ð¶î¸³Óè±íc ×ÜÕËÃ÷ϸ±í´û·½½ð¶î¼Ç¼¸³Óè±íd
select sum(iAOutPrice) as iAOutPrice,cpzid into c from ia_subsidiary where imonth=5 and cinvhead=¡¯1406¡ä and not cPZID is null and not iAOutPrice is null group by cpzid
select ino_id,sum(mc) as mc,coutno_id into d from gl_accvouch where iperiod=5 and ccode=¡¯1406¡ä and coutsysname=¡¯ia¡¯ and ibook = 1 and iflag is null and mc<>0 group by ino_id,coutno_id
¨C2.1.1 ²éѯ³öÊÕÈë´íÎóµÄƾ֤ºÅ
select * from b where coutno_id not in (select cpzid from a) or
coutno_id in (select cpzid from a inner join b on a.cpzid=b.coutno_id where a.iainprice<>b.md)
¨C2.2.1²éѯ³ö·¢³ö´íÎóµÄƾ֤ºÅ
select * from d where coutno_id not in (select cpzid from c) or
coutno_id in (select c.cpzid from c inner join d on c.cpzid=d.coutno_id where c.iaoutprice<>d.mc)
¨C¼ÆËã³ö¡°ºËËãºÏ¼Æ¡±=¡°ÓɺËËãÖÆµ¥µÄ×ÜÕ˺ϼơ±¼´¿É
¨C²éѯ¶ÔÓ¦µÄ´æ»õÃ÷ϸ
select sum(iainprice) as [ÊÕÈë½ð¶îºÏ¼Æ],sum(iaoutprice) as [·¢³ö½ð¶îºÏ¼Æ] from ia_subsidiary
where cpzid in (¡¯2012IA0000000001096¡ä)
select cbustype as [ÒµÎñÀàÐÍ],cvoucode as [µ¥¾ÝºÅ],cwhcode as [²Ö¿â±àÂë],cinvcode as [´æ»õ±àÂë],iainprice as [ÊÕÈë½ð¶î],iaoutprice as [·¢³ö½ð¶î],* from ia_subsidiary
where cpzid in (¡¯2012IA0000000001096¡ä)
¨Cɾ³ýÁÙʱ±í
¨Cdrop table a drop table b drop table c drop table d
Õ˶ÔÕ˵ŦÄÜʱ³öÏÖ´æ»õºËËãÄ£¿éÓë×ÜÕËÄ£¿é¶ÔÕ˲»Æ½µÄÏÖÏó£¬ÓÃÓÑ֪ʶ¿â·ÖÎöÖ÷ÒªÔÒòÈçÏ£º
´æ»õϵͳÖеÄÓë×ÜÕ˶ÔÕË»·½Ú£¬¾³£·¢ÏÖ´æ»õϵͳµÄÆÚ³õ/ÊÕ·¢´æÓë×ÜÕËµÄÆÚ³õ/ÊÕ·¢´æÊý¾Ý²»Ò»Ö¡£ ´æ»õÓë×ÜÕ˶ÔÕ˲»Æ½£¬´æ»õϵͳÊǵ¥¾Ý¼ÇÍêÕ˵ÄÊý¾Ý£¬×ÜÕËÊÇÆ¾Ö¤¼ÇÕËÍêµÄÊý¾Ý£¬¹é¼¯ÆðÀ´³£¼ûµÄÓУº
1¡¢Ç°ÆÚÔ·ݾÍÒѶÔÕ˲»Æ½£¬µ¼ÖºóÆÚÔ·ÝÒ²²»Æ½
2¡¢´æ»õÆÚ³õÓà¶îδָ¶¨¿ÆÄ¿
3¡¢´æ»õϵͳ¼ÇÍêÕË£¬µ«µ±ÔÂδÉú³Éƾ֤
4¡¢×ÜÕ˵Ĵæ»õÀà¿ÆÄ¿³ýÁË´æ»õϵͳ´«µÝÍ⣬×ÔÉí»òÆäËüϵͳҲ»áʹÓôæ»õÀà¿ÆÄ¿
5¡¢´æ»õϵͳÀïµÄµ¥¾Ý¼Ç¼¶ªÊ§Æ¾Ö¤Ë÷ÒýºÅ
6¡¢ÓÉËÄÉáÎåÈëÓÐβ²îµ¼Ö¶ÔÕ˲»Æ½ÈçͼÀýʾ£º
¡¾½â¾ö·½·¨¡¿