ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
SQLÓïÑÔÒÕÊõ(PDF¸ñʽ)-µÚ10²¿·Ö
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡
×ܽ᣺ÓÅÐãµÄ²éѯδ±ØÀ´×ÔÓÅÐãµÄ³ÌÐò¡£¡¡
Êý¾ÝÉ¢²¼¡¡
Data¡¡Dispersion¡¡
µ±Ìõ¼þÊÇ¡°·ÇΨһÐÔ¡±µÄ£¬»òÕßÌõ¼þÒÔΨһÐÔË÷ÒýÉϵķ¶Î§À´±í´ïʱ£¬DBMS¡¡¾Í±ØÐëÖ´Ðз¶Î§É¨¡¡
Ãè¡£ÀýÈ磺¡¡
where¡¡customer_id¡¡between¡¡¡£¡£¡£and¡£¡£¡£¡¡
»ò£º¡¡
where¡¡supplier_name¡¡like¡¡'SOMENAME£¥'¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡51¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¼ü¶ÔÓ¦µÄ¼Ç¼ºÜ¿ÉÄÜÉ¢²¼ÔÚÕû¸ö±íÖУ¬¶ø»ùÓڳɱ¾µÄÓÅ»¯Æ÷ÖªµÀÕâÒ»µã¡£ËùÒÔ£¬Ë÷Òý·¶Î§É¨Ãè¡¡
»áʹ¡¡DBMS¡¡ºËÐÄÖðÒ»¶ÁÈ¡±íµÄ´æ´¢Ò³£¬´Ëʱ£¬ÓÅ»¯Æ÷»á¾ö¶¨¡¡DBMS¡¡ºËÐĺöÂÔË÷Òý¶Ô±í½øÐС¡
ɨÃè¡£¡¡
ÈçµÚ5ÕÂËùÊö£¬Ðí¶àÊý¾Ý¿âϵͳÌṩÁËÖîÈç·ÖÇø£¨partition£©ºÍ¾Û¼¯Ë÷Òý£¨clustered¡¡index£©µÈ¹¦¡¡
ÄÜ£¬Ö±½Ó½«¿ÉÄÜÒ»²¢¶ÁÈ¡µÄÊý¾Ý´æ´¢ÔÚÒ»Æð¡£Æäʵ£¬Êý¾Ý²åÈë´¦ÀíÒ²³£Ôì³ÉÊý¾Ý´Ô¾Û£¨clumping£©¡¡
±£´æµÄÏÖÏó£ºÈç¹ûÿÌõ¼Ç¼²åÈë±íʱ¶¼Òª¼Óʱ¼ä´Á£¨timestamp£©£¬ÔòÏà¼Ì²åÈëµÄ¼Ç¼»á±Ë´Ë½ô¡¡
ÁÚ£¨³ý·ÇÎÒÃDzÉÈ¡ÌØÊâÊֶαÜÃâ×ÊÔ´¾ºÕù£¬¼ûµÚ9ÕµÄÌÖÂÛ£©¡£ÕâÆäʵûÓбØÒª£¬¶øÇÒ¹ØϵÀíÂÛ¡¡
ÖÐҲûÓС°Ë³Ðò¡±µÄ¸ÅÄµ«ÔÚʵ¼ÊÖÐÈ´ºÜ¿ÉÄÜ·¢Éú¡£¡¡
Òò´Ë£¬µ±ÎÒÃÇÔÚʱ¼ä´Á×ֶεÄË÷ÒýÉÏÖ´Ðз¶Î§É¨Ãè¡¢²éѯʱ¼äÉϽӽüµÄË÷ÒýÏîʱ£¬ÕâЩ¼Ç¼¿É¡¡
Äܱ˴˽ôÁÚ¡ª¡ªÈç¹ûÌØÒâΪ´ËÉèÖÃÁ˴洢ѡÏî²ÎÊý£¬¾Í¸üÊÇÈç´ËÁË¡£¡¡
ÏÖÔÚ×öÒ»¸ö¼Ù¶¨£º¼üÖµÓëÌض¨²åÈë»·¾³Î޹ء¢Óë´æ´¢ÉèÖÃÎ޹أ¬Óë¼üÖµ£¨»ò¼üÖµ·¶Î§£©¶ÔÓ¦µÄ¡¡
¼Ç¼¿ÉÄÜ´æ´¢ÔÚ´ÅÅ̵ÄÈκÎλÖá£Ë÷Òý½öÒÔÌض¨Ë³ÐòÀ´´æ´¢¼üÖµ£¬¶ø¶ÔÓ¦µÄ¼Ç¼Ëæ»úÉ¢ÂäÔÚ±í¡¡
ÖС£´Ëʱ£¬Èô¼È²»·ÖÇø¡¢Ò²²»²ÉÓþۼ¯Ë÷Òý£¬ÔòÐè·ÃÎʵĴ洢Çø»á¸ü¶à¡£ÓÚÊÇ£¬¿ÉÄܳöÏÖÏÂÁС¡
Çé¿ö£ºÍ¬Ò»¸ö±íÉÏÓÐÁ½¸ö¿ÉÑ¡ÔñÐÔÍêÈ«ÏàͬµÄË÷Òý£¬µ«Ò»¸öË÷ÒýÐÔÄܺá¢Ò»¸öË÷ÒýÐÔÄܲÕâ¡¡
ÖÖÇé¿öÔÚµÚ3ÕÂÒÑÌáµ½¹ý£¬ÏÂÃæÀ´·ÖÎöһϡ£¡¡
ΪÁË˵Ã÷ÉÏÊöÇé¿ö£¬ÏÈ´´½¨Ò»¸ö¾ßÓС¡1000000Ìõ¼Ç¼µÄ±í£¬Õâ¸ö±íÓС¡c1¡¢c2ºÍ¡¡c3¡¡Èý¸ö×ֶΣ¬¡¡
c1¡¡±£´æÐòºÅ£¨1¡¡µ½¡¡1¡¡000000£©£¬c2¡¡±£´æ´Ó¡¡1¡¡µ½¡¡2¡¡000000¡¡²»µÈµÄËæ»úÊý£¬c3¡¡±£´æ¿ÉÖظ´¡¢¡¡
ÇÒ¾³£Öظ´µÄËæ»úÖµ¡£±íÃæ¿´À´£¬c1¡¡ºÍ¡¡c2¡¡¶¼¾ßΨһÐÔ£¬Òò´Ë¾ßÓÐÍêÈ«ÏàͬµÄ¿ÉÑ¡ÔñÐÔ¡£Ë÷Òý¡¡
½¨ÔÚc1ÉÏ£¬Ôò±íÖÐ×ֶεÄ˳Ðò£¬ÓëË÷ÒýÖеÄ˳ÐòÏà·û¡ª¡ªµ±È»£¬Êµ¼ÊÉÏ£¬¶Ô±íµÄɾ³ý²Ù×÷»áÁô¡¡
Ï¡°¿Õ¶´¡±£¬ËæºóÓÖÓÐеIJåÈë¼Ç¼ÌîÈ룬ËùÒԼǼ˳Ðò»á±»´òÂÒ¡£Ïà±È֮ϣ¬Ë÷Òý½¨ÔÚc2ÉÏ£¬¡¡
Ôò±íÖмǼ˳ÐòÓëË÷ÒýÖеÄ˳ÐòÎ޹ء£¡¡
ÏÂÃæ¶ÁÈ¡c3¡¡£¬Ê¹ÓÃÈçÏ·¶Î§Ìõ¼þ£º¡¡
where¡¡column_name¡¡between¡¡some_value¡¡andsome_value¡¡£«10¡¡
Èçͼ6¡1Ëùʾ£¬Ê¹ÓÃc1Ë÷Òý£¨ÓÐÐòË÷Òý£¬Ë÷ÒýÖмüµÄ˳ÐòÓë±íÖмǼ˳ÐòÏàͬ£©ºÍc2Ë÷Òý£¨Ëæ»ú¡¡
Ë÷Òý£©µÄÐÔÄܲîÒìºÜ´ó¡£±ðÍüÁËÔì³ÉÕâÖÖ²îÒìµÄÔÒò£ºÎªÁ˶ÁÈ¡c3µÄÖµ£¬³ýÁË·ÃÎÊË÷Òý£¬»¹Òª¡¡
·ÃÎÊ±í¡£Èç¹ûÎÒÃÇÓÐÁ½¸ö¸´ºÏË÷Òý£¬·Ö±ðÔÚ¡¡£¨c1£»c3£©¡¡ºÍ¡¡£¨c2£»c3£©¡¡ÉÏ£¬¾Í²»»áÓÐÉÏÊö²îÒìÁË£¬Òò¡¡
ΪÕâʱ²»±Ø·ÃÎÊ±í£¬´ÓË÷ÒýÖм´¿É»ñµÃÒª·µ»ØµÄÄÚÈÝ¡£¡¡
ͼ6¡1˵Ã÷µÄÕâÖÖÐÔÄܲîÒ죬Ҳ½âÊÍÁËÏÂÊöÇé¿öµÄÔÒò£ºÓÐʱÐÔÄÜ»áËæʱ¼ä¶ø½µµÍ£¬ÓÈÆäÊÇÔÚС¡
ϵͳ¸ÕͶÈëÉú²ú»·¾³²¢µ¼Èë¾ÉϵͳµÄ´óÁ¿Êý¾Ýʱ¡£×î³õ¼ÓÔصÄÊý¾ÝµÄÎïÀíÅÅÐò£¬¿ÉÄÜÊÇÓÐÀûÓÚ¡¡
Ìض¨²éѯµÄ£»µ«Ëæºó¼¸¸öÔµĸ÷ÖֻÆÆ»µÁËÕâÖÖ˳Ðò£¬ÓÚÊÇÐÔÄÜ¡°ÉñÃØ¡±½µµÍ¡¡30£¥¡«40£¥¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡52¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ͼ6¡1£º¡°Ë÷ÒýÏî˳ÐòÓë±íÖмǼ˳ÐòÊÇ·ñÒ»Ö¡±¶ÔÐÔÄܵÄÓ°Ïì¡¡
ÏÖÔÚºÜÇå³þÁË£¬¡°DBA¿ÉÒÔËæʱÖØÐÂ×éÖ¯Êý¾Ý¿â¡±ÆäʵÊÇ´íÎóµÄ¡£Êý¾Ý¿âµÄÖØÐÂ×éÖ¯ÔøÒ»¶ÈÁ÷ÐУ»¡¡
µ«²»¶ÏÔö¼ÓµÄÊý¾ÝÁ¿¼°999999£¥¡¡Õý³£ÔËÐеÈÒªÇó£¬Ê¹µÃÖØÐÂ×éÖ¯Êý¾Ý¿â±äµÃ²»ÔÙÊʺϡ£Èç¹û¡¡
ÎïÀí´æ´¢·½Ê½ºÜÖØÒª£¬ÔòÓ¦¿¼ÂǵÚ5ÕÂÌÖÂÛ¹ýµÄ¡°×Ô×éÖ¯½á¹¹£¨self¡organizing¡¡structure£©¡±Ö®Ò»£¬¡¡
ÀýÈç¾Û¼¯Ë÷Òý£¨clustered¡¡indexe£©»òË÷Òý×éÖ¯±í£¨index¡organized¡¡table£©¡£µ«Òª¼Çס£¬¶ÔijÖÖÀà¡¡
Ð͵IJéѯÓÐÀû£¬¿ÉÄܶÔÁíÒ»ÖÖÀàÐ͵IJéѯ²»Àû£¬ÓãÓëÐÜÕƲ»¿ÉµÃ¼æ¡£¡¡
×ܽ᣺ÀàËƵÄË÷Òý£¬ÐÔÄÜÈ´²»Í¬£¬Õâ¿ÉÄÜÊÇÎïÀíÊý¾ÝµÄÉ¢²¼ÒýÆðµÄ¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡°¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡±¡¡
Ìõ¼þµÄ¡°¡°¿ÉË÷ÒýÐÔ¡±¡±¡¡
Criterion¡¡Indexability¡¡
¶Ô¡°Ð¡½á¹û¼¯£¬Ö±½ÓÌõ¼þ¡±µÄÇé¿ö¶øÑÔ£¬Êʵ±µÄË÷Òý·Ç³£ÖØÒª¡£µ«ÊÇ£¬ÆäÖÐÒ²Óв»ÊʺϼÓË÷ÒýµÄ¡¡
ÀýÍâÇé¿ö£ºÒÔÏ°¸Àý£¬ÓÃÀ´Åжϻá¼ÆÕËÄ¿ÊÇ·ñ´æÔÚ¡°½ð¶î²»Æ½¡±µÄÇé¿ö£¬ËäÈ»¿ÉÑ¡ÔñÐԺܸߣ¬µ«¡¡
²»ÊʺϼÓË÷Òý¡£¡¡
´ËÀýÖУ¬Óиö±íglreport£¬¸Ã±í°üº¬Ò»¸öӦΪ0µÄ×Ö¶Îamount_diff¡£´Ë²éѯµÄÄ¿µÄÊÇҪ׷×Ù»á¼Æ´í¡¡
Î󣬲¢ÕÒ³öamount_diff²»ÊÇ0µÄ¼Ç¼¡£¼ÈȻʹÓÃÁËÏÖ´úµÄDBMS£¬Ö±½Ó°ÑÕËÄ¿¶ÔÓ¦³É±í£¬²¢Ó¦Óá¡
´ÓÇ°¡°Ö½±Ê¼ÇÕË¡±µÄÂß¼£¬ÊµÔÚÓеãÎÊÌ⣻µ«ºÜ²»ÐÒ£¬ÎÒÃǾ³£Óöµ½ÕâÖÖÓÐÎÊÌâµÄÊý¾Ý¿â¡£ÎÞÂÛ¡¡
Éè¼ÆµÄÖÊÁ¿ÈçºÎ£¬Ïñamount_diffÕâÑùµÄ×ֶΡ¡
ͨ³£²»Ó¦¼ÓË÷Òý£¬ÒòΪÔÚÀíÏëÇé¿öÏÂÿÌõ¼Ç¼µÄamount_diff×ֶζ¼ÊÇ¡¡0¡£´ËÍ⣬amount_diff×Ö¡¡
¶ÎÃ÷ÏÔÊÇ¡°·Ç¹æ·¶»¯¡±Éè¼ÆµÄ½á¹û£¬´óÁ¿¼ÆËãÒª²Ù×÷¸Ã×ֶΡ£Î¬»¤Ò»¸ö¼ÆËã×Ö¶ÎÉϵÄË÷Òý£¬´ú¼Û¡¡
Òª¸ßÓÚ¾²Ì¬×Ö¶ÎÉϵÄË÷Òý£¬ÒòΪ±»Ð޸ĵļü»áÔÚË÷ÒýÄÚ¡°Òƶ¯¡±£¬ÓÚÊÇË÷ÒýÒª³ÐÊܵĿªÏú±È¼òµ¥¡¡
½ÚµãÔö£¯É¾Òª¸ß¡£¡¡
×ܽ᣺²¢·ÇËùÓÐÃ÷È·µÄÌõ¼þ¶¼ÊʺϼÓË÷Òý¡£ÌرðÊÇ£¬Æµ·±¸üеÄ×ֶλáÔö¼ÓË÷Òýά»¤µÄ³É±¾¡£¡¡
»Øµ½Àý×Ó¡£¿ª·¢ÕßÓÐÌìÀ´ÕÒÎÒ£¬ËµËûÒÑ×î¼Ñ»¯ÁËÒÔÏ¡¡Oracle¡¡²éѯ£¬²¢Ñ¯Îʹýר¼Ò½¨Ò飺¡¡
select¡¡
total¡£deptnum£»¡¡
total¡£accounting_period£»¡¡
total¡£ledger£»¡¡
total¡£cnt£»¡¡
error¡£err_cnt£»¡¡
cpt_error¡£bad_acct_count¡¡
from¡¡
¡¡Firstin¡line¡¡view¡¡
£¨select¡¡
deptnum£»¡¡
accounting_period£»¡¡
ledger£»¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡53¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
count£¨account£©¡¡cnt¡¡
from¡¡
glreport¡¡
groupby¡¡
deptnum£»¡¡
ledger£»¡¡
accounting_period£©¡¡total£»¡¡
¡¡Second¡¡in¡line¡¡view¡¡
£¨select¡¡
deptnum£»¡¡
accounting_period£»¡¡
ledger£»¡¡
count£¨account£©¡¡err_cnt¡¡
from¡¡
glreport¡¡
where¡¡
amount_diff0¡¡
groupby¡¡
deptnum£»¡¡
ledger£»¡¡
accounting_period£©¡¡error£»¡¡
¡¡Third¡¡in¡line¡¡view¡¡
£¨select¡¡
deptnum£»¡¡
accounting_period£»¡¡
ledger£»¡¡
count£¨distinct¡¡account£©¡¡bad_acct_count¡¡
from¡¡
glreport¡¡
where¡¡
amount_diff0¡¡
groupby¡¡
deptnum£»¡¡
ledger£»¡¡
accounting_period¡¡
£©cpt_error¡¡
where¡¡
total¡£deptnum¡¡=error¡£deptnum£¨£«£©¡¡and¡¡
total¡£accounting_period¡¡=error¡£accounting_period£¨£«£©¡¡and¡¡
total¡£ledger¡¡=error¡£ledger£¨£«£©and¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡54¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
total¡£deptnum¡¡=cpt_error¡£deptnum£¨£«£©¡¡and¡¡
total¡£accounting_period¡¡=cpt_error¡£accounting_period£¨£«£©¡¡and¡¡
total¡£ledger¡¡=cpt_error¡£ledger£¨£«£©¡¡
order¡¡by¡¡
total¡£deptnum£»¡¡
total¡£accounting_period£»¡¡
total¡£ledger¡¡
Íâ²ã²éѯwhere×Ó¾äÖеġ°£¨£«£©¡±ÊÇOracle¡¡ÌØÓеÄÓï·¨£¬´ú±íÍâÁ¬½Ó£¨outerjoin£©¡£»»ÑÔÖ®£º¡¡
select¡¡whatever¡¡
from¡¡ta£»¡¡
tb¡¡
where¡¡ta¡£id=tb¡£id¡¡£¨£«£©¡¡
Ï൱ÓÚ£º¡¡
select¡¡whatever¡¡
from¡¡ta¡¡
outerjoin¡¡tb¡¡
on¡¡tb¡£id=ta¡£id¡¡
ÏÂÁÐSQL*PlusÊä³öÏÔʾÁ˸òéѯµÄÖ´Ðмƻ®£º¡¡
10£º16£º57SQL¡·¡¡set¡¡autotracetraceonly¡¡
10£º17£º02SQL¡·¡¡/¡¡
37rows¡¡selected¡£¡¡
Elapsed£º¡¡00£º30£º00¡£06¡¡
Execution¡¡Plan¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
0¡¡¡¡¡¡¡¡¡¡SELECTSTATEMENTOptimizer=CHOOSE¡¡
£¨Cost=1779554¡¡Card=154Bytes=16170£©¡¡
1¡¡¡¡0¡¡MERGEJOIN£¨OUTER£©£¨Cost=1779554¡¡Card=154Bytes=16170£©¡¡
2¡¡¡¡1¡¡¡¡MERGEJOIN£¨OUTER£©£¨Cost=1185645¡¡Card=154¡¡Bytes=10780£©¡¡
3¡¡¡¡2¡¡¡¡¡¡¡¡¡¡¡¡¡¡VIEW£¨Cost=591736¡¡Card=154Bytes=5390£©¡¡
4¡¡¡¡3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡SORT£¨GROUPBY£©£¨Cost=591736¡¡Card=154Bytes=3388£©¡¡
5¡¡¡¡4¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TABLEACCESS£¨FULL£©¡¡OF'GLREPORT'¡¡
£¨Cost=582346¡¡Card=4370894Bytes=96159668£©¡¡
6¡¡¡¡2¡¡¡¡¡¡¡¡¡¡¡¡¡¡SORT£¨JOIN£©£¨Cost=593910¡¡Card=154Bytes=5390£©¡¡
7¡¡¡¡6¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡VIEW¡¡£¨Cost=593908Card=154Bytes=5390£©¡¡
8¡¡¡¡7¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡SORT£¨GROUP¡¡BY£©£¨Cost=593908¡¡Card=154Bytes=4004£©¡¡
9¡¡¡¡8¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TABLEACCESS£¨FULL£©¡¡OF'GLREPORT'¡¡
£¨Cost=584519¡¡Card=4370885Bytes=113643010£©¡¡
10¡¡¡¡1¡¡¡¡SORT£¨JOIN£©£¨Cost=593910¡¡Card=154Bytes=5390£©¡¡
11¡¡10¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡VIEW£¨Cost=593908¡¡Card=154Bytes=5390£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡55¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
12¡¡11¡¡¡¡¡¡¡¡¡¡¡¡SORT£¨GROUPBY£©£¨Cost=593908Card=154¡¡Bytes=5698£©¡¡
13¡¡12¡¡¡¡¡¡¡¡¡¡¡¡¡¡TABLEACCESS£¨FULL£©¡¡OF'GLREPORT'¡¡
£¨Cost=584519¡¡Card=4370885Bytes=161722745£©¡¡
Statistics¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
193¡¡recursive¡¡calls¡¡
0¡¡db¡¡block¡¡gets¡¡
3803355consistent¡¡gets¡¡
3794172¡¡physical¡¡reads¡¡
1620¡¡redo¡¡size¡¡
2219¡¡bytes¡¡sentvia¡¡SQL*Net¡¡toclient¡¡
677bytes¡¡received¡¡via¡¡SQL*Net¡¡from¡¡client¡¡
4¡¡SQL*Net¡¡roundtrips¡¡to/from¡¡client¡¡
17¡¡sorts£¨memory£©¡¡
0¡¡sorts¡¡£¨disk£©¡¡
37¡¡rows¡¡processed¡¡
ÔÚ´Ë˵Ã÷£¬ÎÒûÓÐÀË·ÑÌ«¶àʱ¼äÔÚÖ´Ðмƻ®ÉÏ£¬ÒòΪ²éѯ±¾ÉíµÄÎÄ×ÖÃèÊöÒÑÏÔʾÁ˲éѯµÄ×î´ó¡¡
Ìص㣺ֻÓÐËÄ~Îå°ÙÍòÌõ¼Ç¼µÄglreport±í£¬±»·ÃÎÊÁËÈý´Î£»Ã¿¸ö×Ó²éѯ´æÈ¡Ò»´Î£¬¶øÇÒÿ´Î¶¼¡¡
ÊÇÍêȫɨÃè¡£¡¡
±àд¸´ÔÓ²éѯʱ£¬Ç¶Ìײéѯͨ³£ºÜÓÐÓã¬ÓÈÆäÊÇÄã¼Æ»®½«²éѯ»®·ÖΪ¶à¸ö²½Ö裬ÿ¸ö²½Öè¶ÔÓ¦¡¡
Ò»¸ö×Ó²éѯ¡£µ«ÊÇ£¬Ç¶Ìײéѯ²»ÊÇÒøµ¯£¬ÉÏÊöÀý×Ó¾ÍÊôÓÚ¡°ÀÄÓÃǶÌײéѯ¡±¡£¡¡
²éѯÖеĵÚÒ»¸öÄÚǶÊÓͼ£¬¼ÆËãÿ¸ö²¿ÃŵÄÕËÄ¿Êý¡¢»á¼ÆÆÚ¡¢·ÖÀàÕË£¬Õâ²»¿É±ÜÃâµØÒª½øÐÐÈ«¡¡
±íɨÃè¡£Ãæ¶ÔÏÖʵ°É£¡ÎÒÃDZØÐëÍêÕûɨÃèglreport±í£¬ÒòΪ¼ì²éÓжàÉÙ¸öÕËÄ¿Éæ¼°ËùÓмǼ¡£µ«¡¡
ÊÇ£¬ÓбØҪɨÃèµÚ¶þ´ÎÉõÖÁµÚÈý´ÎÂ𣿡¡
×ܽ᣺Èç¹û±ØÐë½øÐÐÈ«±íɨÃ裬±íÉϵÄË÷Òý¾ÍûÓÃÁË¡£¡¡
²»Òªµ¥´Ó¡°·ÖÎö£¨analytic£©¡±µÄ¹Ûµã¿´´ý´¦Àí£¬»¹ÒªÍËÒ»²½£¬´ÓÕûÌå½Ç¶È¿¼ÂÇ¡£³ýÁËÔÚ¡¡amount_diff¡¡
ÖµÉϵÄÌõ¼þÖ®Í⣬µÚ¶þ¸öÄÚǶÊÓͼËù×öµÄ¼ÆË㣬ÓëµÚÒ»¸öÊÓͼÍêÈ«Ïàͬ¡£ÎÒÃÇûÓбØҪʹÓá¡
count£¨£©¼ÆËã×ÜÊý£¬¿ÉÒÔÔÚamount_diif²»ÊÇ¡¡0¡¡Ê±¼Ó¡¡1£¬·ñÔò¼Ó0£¬Í¨¹ý¡¡Oracle¡¡ÌØÓеġ¡decode£¨u£»¡¡v¡¡
w£»¡¡x£©¡¡º¯Êý£¬»òʹÓñê×¼Óï·¨case¡¡when¡¡u=vthen¡¡welsexend£¬¼´¿ÉÇáËÉʵÏÖÕâÏî¼ÆËã¡£¡¡
µÚÈý¸öÄÚǶÊÓͼËù¹ýÂ˵ļǼÓëµÚÒ»¸öÊÓͼÏàͬ£¬µ«Òª¼ÆË㲻ͬÕËÄ¿Êý¡£°ÑÕâ¸ö¼ÆÊýºÏ²¢µ½µÚ¡¡
Ò»¸ö×Ó²éѯÖв¢²»ÄÑ£ºÓÃchr£¨1£©´ú±íamount_diff¡¡Îª¡¡0¡¡Ê±µÄ¡°ÕË»§±àºÅ£¨account¡¡number£©¡±£¬¾ÍºÜ¡¡
ÈÝÒ×ͳ¼ÆÓжàÉÙ¸ö²»Í¬µÄÕË»§±àºÅÁË£¬µ±È»£¬¼Çס¼õ1È¥µôchr£¨1£©Õâ¸öÐéÄâµÄÕË»§±àºÅ¡£ÆäÖУ¬¡¡
ÕË»§±àºÅ×ֶεÄÀàÐÍΪvarchar2£¨×¢1£©£¬¶øchr£¨1£©ÔÚ¡¡Oracle¡¡Öдú±íASCIIÂëֵΪ¡¡1¡¡µÄ×Ö·û¡ª¡ª¡¡
ÔÚʹÓá¡Oracle¡¡ÕâÀàÓá¡C¡¡ÓïÑÔ±àдµÄϵͳʱ£¬ÎÒ×ÜÊDz»¸Ò°²ÐÄʹÓÃchr£¨0£©£¬ÒòΪ¡¡CÓïÑÔ¡¡ÒÔ¡¡
chr£¨0£©×÷Ϊ×Ö·û´®ÖÕÖ¹·û¡£¡¡
Sothis¡¡is¡¡thesuggestion¡¡thatI¡¡returnedtothe¡¡developer£º¡¡
select¡¡deptnum£»¡¡
accounting_period£»¡¡
ledger£»¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡56¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
count£¨account£©¡¡nb£»¡¡
sum£¨decode£¨amount_diff£»0£»0£»1£©£©err_cnt£»¡¡
count£¨distinct¡¡decode£¨amount_diff£»0£»chr£¨1£©£»account£©£©¡1¡¡
bad_acct_count¡¡
from¡¡
glreport¡¡
groupby¡¡
deptnum£»¡¡
ledger£»¡¡
accounting_period¡¡
Õâ¸öеIJéѯ£¬Ö´ÐÐËÙ¶ÈÊÇÔÏȵÄËı¶¡£ÕâË¿ºÁ²»ÁîÈËÒâÍ⣬ÒòΪÈý´ÎµÄÍêÕûɨÃè±ä³ÉÁËÒ»´Î¡£¡¡
×¢Ò⣬²éѯÖв»ÔÙÓÐwhere×Ӿ䣺amount_diffÉϵÄÌõ¼þÒѱ»¡°Ç¨ÒÆ¡±µ½ÁËselectÁбíÖÐdecode£¨£©º¯Êý¡¡
Ö´ÐеÄÂß¼£¬ÒÔ¼°ÓÉgroupby×Ó¾äÖ´Ðеľۺϣ¨aggregation£©ÖС£¡¡
ʹÓþۺϴúÌæ¹ýÂËÌõ¼þÓеãÌØÊ⣬ÕâÕýÊÇÎÒÃÇҪ˵Ã÷µÄ¡°¾ÅÖÖµäÐÍÇé¿ö¡±ÖеÄÁíÒ»ÖÖ¡ª¡ª¡¡ÒԾۺϡ¡
º¯ÊýΪ»ù´¡»ñµÃ½á¹û¼¯¡£¡¡
×ܽ᣺ÄÚǶ²éѯ¿ÉÒÔ¼ò»¯²éѯ£¬µ«ÈôʹÓò»É÷£¬¿ÉÄÜÔì³ÉÖظ´´¦Àí¡£¡¡
С½á¹û¼¯£¬¼ä½ÓÌõ¼þ¡¡
Small¡¡Result¡¡Set£»¡¡Indirect¡¡Criteria¡¡
ÓëÉÏÒ»½ÚÀàËÆ£¬ÕâÒ»½ÚÒ²ÊÇÒª»ñȡС½á¹û¼¯£¬Ö»ÊDzéѯÌõ¼þ²»ÔÙÕë¶ÔÔ´±í£¬¶øÊÇÕë¶ÔÆäËû±í¡£¡¡
ÎÒÃÇÏëÒªµÄÊý¾ÝÀ´×ÔÒ»¸ö±í£¬µ«²éѯÌõ¼þÊÇÕë¶ÔÆäËû±íµÄ£¬ÇÒ²»ÐèÒª´ÓÕâЩ±í·µ»ØÈκÎÊý¾Ý¡£¡¡
µäÐ͵ÄÀý×ÓÊÇÔÚµÚ4ÕÂÌÖÂÛ¹ýµÄ¡°ÄÄЩ¿Í»§¶©¹ºÁËÌض¨ÉÌÆ·¡±ÎÊÌâ¡£ÈçµÚ4ÕÂËùÊö£¬ÕâÀà²éѯ¿ÉÓá¡
Á½ÖÖ·½·¨±í´ï£º¡¡
ʹÓÃÁ¬½Ó£¬¼ÓÉÏ¡¡distinct¡¡È¥³ý½á¹ûÖеÄÖظ´¼Ç¼£¬ÒòΪÓеĿͻ§»á¶à´Î¶©¹ºÏàͬÉÌÆ·¡¡
ʹÓùØÁª»ò·Ç¹ØÁª×Ó²éѯ¡¡
Èç¹û¿ÉÒÔʹÓÃ×÷ÓÃÓÚÔ´±íµÄÌõ¼þ£¬Çë²Î¿¼Ç°Ò»½Ú¡°Ð¡½á¹û¼¯£¬Ö±½ÓÌõ¼þ¡±Öеķ½·¨¡£µ«Èç¹ûÕÒ²»¡¡
µ½ÕâÑùµÄÌõ¼þ£¬¾Í±ØÐë¶à¼ÓСÐÄÁË¡£¡¡
È¡ÓõÚ4ÕÂÖÐÀý×ӵļò»¯°æ±¾£¬ÕÒ³ö¶©¹ºòùò𳵵Ŀͻ§£¬µäÐÍʵÏÖÈçÏ£º¡¡
select¡¡distinct¡¡orders¡£custid¡¡
from¡¡orders¡¡
join¡¡orderdetail¡¡
on¡¡£¨orderdetail¡£ordid¡¡=orders¡£ordid£©¡¡
join¡¡articles¡¡
on¡¡£¨articles¡£artid=orderdetail¡£artid£©¡¡
where¡¡articles¡£artname¡¡='BATMOBILE'¡¡
ÒÀÎÒ¿´£¬Ã÷ȷʹÓÃ×Ó²éѯÀ´¼ì²é¿Í»§¶©µ¥ÊÇ·ñ°üº¬Ä³ÏîÉÌÆ·£¬²ÅÊǽϺõķ½Ê½£¬¶øÇÒÒ²±È½ÏÈÝ¡¡
Ò×Àí½â¡£µ«Ó¦¸Ã²ÉÓá°¹ØÁª×Ó²éѯ¡±»¹ÊÇ¡°·Ç¹ØÁª×Ó²éѯ¡±ÄØ£¿ÓÉÓÚÎÒÃÇûÓÐÆäËûÌõ¼þ£¬ËùÒԴ𰸡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡57¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
Ó¦¸ÃºÜÇå³þ£º·Ç¹ØÁª×Ó²éѯ¡£·ñÔò£¬¾Í±ØÐëɨÃèorders±í£¬²¢Õë¶ÔÿÌõ¼Ç¼ִÐÐ×Ó²éѯ¡ª¡ªµ±orders¡¡
±í¹æģСʱͨ³£²»»á²é¾õÆäÖÐÎÊÌ⣬µ«Ëæ×Åorders±íÔ½À´Ô½´ó£¬ËüµÄÐÔÄܾÍÖð½¥ÈÃÎÒÃÇÈç×øÕëÕ±¡¡
ÁË¡£¡¡
·Ç¹ØÁª×Ó²éѯ¿ÉÒÔÓÃÈçϵľµä·ç¸ñ±àд£º¡¡
select¡¡distinct¡¡orders¡£custid¡¡
from¡¡orders¡¡
where¡¡ordid¡¡in£¨select¡¡orderdetails¡£ordid¡¡
from¡¡orderdetail¡¡
join¡¡articles¡¡
on¡¡£¨articles¡£artid=orderdetail¡£artid£©¡¡
where¡¡articles¡£artname¡¡='BATMOBILE'£©¡¡
»
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾Ñé½±Àø£¬ÈÏÕæдԴ´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾Ñé½±ÀøŶ£¡