»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > VBÎĵµ > ÆäËûÎĵµ
ÓÅ»¯³ÌÐòËÙ¶È
·¢±íÈÕÆÚ£º2003-06-23 00:00:00×÷Õߣº¶ ³ö´¦£º  

ËÙ¶ÈÊdzÌÐòµÄÃü£¬Èç¹ûÄúµÄÈí¼þÔٺ㬵«ÔËÐÐËٶȺÜÂý£¬ÄÇôÄú½«Ê§È¥Óû§ÄÍÐÄ¡£VB6ÔÚ²Ù×ÝÊý¾Ý

¿â·½Ãæ×öµÄºÜ³öÉ«£¬µ«²Ù×ݱíµÄ»¹ÊÇÓÃSQLÓï¾ä¿ì£¬ºÃÔÚVB6µÄDAO¶ÔÏó¡¢ADO¶ÔÏóºÍÊý¾Ý»·¾³¡¢ADO

¿Ø¼þ¶¼¿ÉÒÔʹÓÃSQLÓï¾ä£¬µ«ÔõôÌá¸ßÊý¾Ý²Ù×ÝËÙ¶ÈÄØ£¿½¨Á¢Ë÷Òýµ±È»ÊÇ×î»ù±¾µÄÒªÇ󣬳ý´ËÖ®Íâ

ÄØ£¿ÓÐûÓÐÆäËûµÄ·½·¨£¿µÚÒ»VBÂÛ̳(http://www.d1vb.com)µÄÍøÓѾ­³£Ìá³öÕâ¸öÎÊÌ⣬ÕâÀïÎÒ

¸æËßÄú¼¸ÖÖÓÅ»¯µÄ·½·¨£º

Ò»¡¢±íµÄÉè¼Æ

µ±ÔÚ±íÖÐÌí¼Ó×ֶεÄʱºò,Ó¦¸ÃÑ¡Ôñ³¤¶È×îСµÄÊý¾ÝÀàÐÍ,ÕâÑù±íÔÚÄÚ´æÖÐÿҳ¿ÉÒÔ´æ´¢¸ü¶àµÄ¼Ç

¼¡£È磺¡°ÐÕÃû¡±×Ö¶ÎÒ»°ãÉèÖÃΪTEXTÀàÐÍ£¬³¤¶ÈΪ10Ò»°ã¾Í¹»Óã¬Ôò±ÈĬÈϵÄ255ÒªºÃµÄ¶à¡£Õû

ÐÍIntegerµÄ³¤¶ÈÊÇ2£¬ÔÚʹÓÃÕûÐÍInteger¾Í¿ÉÒÔ½â¾öÎÊÌâµÄµØ·½²»ÒªÊ¹ÓÃSingle¡¢Long¡¢

Double¡¢Currency£¬ÒòΪËüÃǵij¤¶È·Ö±ðΪ£´¡¢£´¡¢£¸¡¢£¸£¬¶¼±È£²´ó¡£ÔÚ½¨Á¢±íºóÒ»¶¨Òª½¨Á¢

Ë÷Òý£¬Õâ¿ÉÒÔ´ó´óÌá¸ß²éѯËٶȣ¬ÊÇÌá¸ßËÙ¶È×î»ù±¾µÄÒªÇó¡£

¶þ¡¢Ñ¹ËõÊý¾Ý¿â

JETÊý¾Ý¿âµÄ²éѯÓÅ»¯ÊÇÓдú¼ÛµÄ£¬Ëæ×ÅÊý¾Ý¿âµÄ²»¶ÏÀ©´ó£¬ÓÅ»¯½«²»ÔÙÆð×÷Óá£Ñ¹ËõÊý¾Ý¿â»á¸Ä

±äÊý¾Ý¿âµÄ״̬£¬²¢ÖØÐÂÓÅ»¯ËùÓвéѯ¡£Í¬Ê±£¬Ëæ×ÅÊý¾Ý¿âµÄÔö´ó£¬»á²úÉúºÜ¶àËéƬ¡£¶øѹËõÊý¾Ý

¿â¿ÉÒÔ°ÑÒ»¸ö±íÖеÄÊý¾ÝÊý¾Ýдµ½Ó²ÅÌÖÐÁ¬ÐøµÄÒ³ÀÌá¸ßÁË˳ÐòËÑË÷µÄËٶȡ£

ѹËõÊý¾Ý¿âʹÓÃCompactDatabaseÃüÁÏÂÃæµÄÓï¾äѹËõÊý¾Ý¿â²¢²úÉúÒ»¸öÊý¾Ý¿â±¸·Ý£º

DBEngine.CompactDatabase ¡°C:\VB\BIBLIO.MDB¡±, ¡°C:\VB\BIBLIO2.MDB¡±

  Kill ¡°C:\VB\BIBLIO.BAK¡±  Name ¡°C:\VB\BIBLIO.MDB¡± As ¡°C:\VB\BIBLIO.BAK¡±

  Name ¡°C:\VB\BIBLIO2.MDB¡± As ¡°C:\VB\BIBLIO.MDB¡±

×¢Ò⣬Èç¹ûÊý¾Ý¿âºÜ´óµÄ»°£¬¿ÉÄÜÐèÒªÕûÒ¹µÄʱ¼äÀ´Ñ¹ËõÊý¾Ý¿â¡£

Èý¡¢±ÜÃâ²éѯÊä³öÀïÃæ¶àÓàµÄ¼ÆËã

µ±²éѯµÄ½á¹û×÷ΪÁíÍâÒ»¸ö²éѯµÄÊý¾ÝÔ´µÄʱºò£¬¿ÉÄÜÒýÆð²éѯÓÅ»¯ÎÊÌâ¡£ÔÚÕâ¸öʱºòµÚÒ»´Î²éѯ

ÀïÃ澡Á¿±ÜÃâ´óÁ¿µÄ¼ÆËã¡£ÔÚÈçÏÂʾÀýÖУ¬Query1ÊǵÚÒ»¸ö²éѯµÄ½á¹û£¬È»ºóËü×÷ΪµÚ¶þ¸ö²éѯ

µÄÊý¾ÝÔ´¡£

Dim DB As Database

Dim RS As RecordSet

  Set DB = DBEngine.Workspaces(0).Opendatabase(¡°Biblio.MDB¡±)

  DB.CreateQueryDef(¡°Query1¡±, _

   ¡°SELECT IIF(Au_ID=1,¡¯Hello¡¯,¡¯Goodbye¡¯) AS X FROM Authors¡±)

  Set RS = DB.OpenRecordSet(¡°SELECT * FROM Query1 WHERE X=¡¯Hello¡¯¡±)

ÓÉÓÚÔÚµÚÒ»¸ö²éѯQuery1ÖеÄIIF()±í´ïʽ²»Äܱ»ÓÅ»¯£¬£¬ËùÒÔÔÚµÚ¶þ¸ö²éѯÖеÄWHERE×Ó¾äÒ²²»

Äܱ»ÓÅ»¯¡£Èç¹ûÒ»¸ö±í´ïʽÔÚÒ»¸ö²éѯÊ÷ÖÐÂñ²ØµÄºÜÉîµÄ»°£¬ÔòÕâ¸ö²éѯ²»¿É±»Ê¹Óã¬ËüÊDz»¿ÉÓÅ

»¯µÄ¡£

Èç¹û¿ÉÄܵĻ°£¬°ÑÕâ¸öSQLÓï¾äºÏ²¢ÎªÒ»¸öûÓÐǶÌ×µÄSQLÓï¾ä£º

Set RS = DB.OpenRecordSet(¡°SELECT * FROM Authors WHERE Au_ID=1¡±)

¶ÔÓÚ¸üÁé»îµÄǶÌײéѯ£¬¾¡Á¿ÔÚSQLÓï¾äÖÐʹÓÃ×Ö¶ÎÃû£¬È磺

DB.CreateQueryDef(¡°Query1¡±, _

   ¡°SELECT IIF(Au_ID=1,¡¯Hello¡¯,¡¯Goodbye¡¯) AS X, Au_ID, FROM Authors¡±)

  Set RS = DB.OpenRecordSet(¡°SELECT * FROM Query1 WHERE Au_ID=1¡±)

Èç¹ûÔÚ²éѯÊä³öÖÐʵÔÚÎÞ·¨±ÜÃâ¼ÆËãʽµÄ»°£¬¾¡Á¿°Ñ¼ÆËãʽ·ÅÔÚ×îÍâ²ã£¬²»Òª·ÅÔÚ×îÄڲ㡣

ËÄ¡¢Ö»Êä³öÐèÒªµÄ×Ö¶Î

ÔÚ½¨Á¢²éѯµÄʱºò£¬½ö·µ»ØÐèÒªµÄ×ֶΣ¬ÕâÑù¿ÉÒÔ½ÚÊ¡²»±ØÒªµÄ¿ªÖ§¡£Èç¹ûij¸ö×ֶβ»ÊÇÄãÐèÒª

µÄ£¬²»ÒªÔÚ²éѯÓï¾äÖгöÏÖ¡£ÉÏÃæµÄÊÂÀýÕý˵Ã÷ÁËÕâ¸öÎÊÌâ¡£

Îå¡¢·Ö×é¡¢ºÏ²¢¼°»ã×Ü

ÕâÀïҪ˵Ã÷µÄÖ÷ÒªÊǺϲ¢£¬µ±ÄãÐèÒª°ÑÁ½¸ö±íºÏ²¢£¬¾ÍÊÇ˵£ºµ±ÄãÒª¸ù¾Ý¡°Customer Name¡±¶ÔÁ½

¸ö±í½øÐкϲ¢£¬Òª¿Ï¶¨GROUP BY field (Customer Name)ºÍ»ã×Ü(Sum, Count, and µÈ)µÄ×Ö¶Î

ÊÇÀ´×ÔͬһÕÅ±í¡£

ÀýÈ磺ÏÂÁÐÓï¾äÓÅ»¯ÐԽϲÒòΪSUM×Ó¾äÀ´×ÔOrd±í£¬¶øGROUP BY×Ó¾äÀ´×ÔCust±í£º

SELECT Cust.CustID,

     FIRST(Cust.CustName) AS CustName,

     SUM(Ord.Price) AS Total

  FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

  GROUP BY Cust.CustID

Èç¹û°´ÕÕOrd.CustID·Ö×飬²éѯÐÔÄܾͺõĶàÁË£º

SELECT Ord.CustID,

     FIRST(Cust.CustName) AS CustName,

     SUM(Ord.Price) AS Total

  FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

  GROUP BY Ord.CustID

Áù¡¢¾¡Á¿¼õÉÙ·Ö×éµÄ×Ö¶Î

SQLÓï¾äÖзÖ×飨GROUP BY£©µÄ×Ö¶ÎÔ½¶à£¬Ö´ÐвéѯµÄʱ¼äÔ½³¤¡£ÔÚGROUP BY×Ó¾äÖо¡Á¿ÓÃ

aggregateº¯ÊýÀ´¼õÉÙ×ֶεÄÊýÁ¿¡£

È磺

GROUP BY As Few Fields As Possible

  SELECT Cust.CustID,

     Cust.CustName,

     Cust.Phone,

     SUM(Ord.Price) AS Total

  FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

  GROUP BY Cust.CustID, Cust.CustName, Cust.Phone

¿ÉÒÔ¸ÄΪ£º: 

  SELECT Ord.CustID,

     FIRST(Cust.CustName) AS CustName,

     FIRST(Cust.Phone) AS Phone,

     SUM(Ord.Price) AS Total

  FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

  GROUP BY Ord.CustID

Æß¡¢Ôںϲ¢Ö®Ç°Ç¶Ì×GROUP BY×Ó¾ä

Èç¹ûÒªºÏ²¢Á½ÕÅ±í£¬¶øÇÒÖ»ÔÚÒ»ÕűíÖзÖ×飬°Ñ²éѯ·ÖΪÁ½¸öSELECTÓï¾äÒª¿ìµÄ¶à¡£

È磺 

  SELECT Ord.CustID,

     FIRST(Cust.CustName) AS CustName,

     FIRST(Cust.Phone) AS Phone,

     SUM(Ord.Price) AS Total

  FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

  GROUP BY Ord.CustID

¿É¸ÄΪ£º 

²éѯ1:

  SELECT CustID, SUM(Price) AS Total

  FROM Ord

  GROUP BY CustID

²éѯ2:

  SELECT Query1.CustID, Cust.CustName, Cust.Phone, Query1.Total

  FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

°Ë¡¢Ôںϲ¢µÄʱºòÁ½±ßµÄ×ֶζ¼ÉèÖÃË÷Òý

Ôںϲ¢±íµÄʱºò£¬¾¡Á¿Ê¹Á½±ßµÄ×ֶζ¼ÉèÖÃË÷Òý¡£ÕâÔÚÖ´ÐвéѯµÄʱºò²éѯÓÅ»¯Æ÷¿ÉÒÔ¸ü¶àµÄʹÓÃ

sophisticated ÄÚ²¿ºÏ²¢²ßÂÔ¡£

µ±È»£¬ÔÚ¹ØϵÐÍÊý¾Ý¿âÖУ¬±íÒªÉè¼ÆµÄ¾¡Á¿Ð¡£¬£¨×îºÃ1-2KÒ³£©£¬ÕâÑùɾ³ý±íµÄË÷ÒýµÄʱºòÒª¿ì

µÄ¶à£¬ÕâÊÇÒòΪÄÚ´æÖжÁÈëÁ˺ÜÉÙµÄÒ³¡£ÕâÐèÒª¸ù¾Ýʵ¼ÊÇé¿ö¶à´Î²âÊÔ¡£

¾Å¡¢Ìí¼ÓË÷ÒýÀ´Ìá¸ß²éѯºÍÅÅÐòµÄËÙ¶È

ΪºÏ²¢»ò²éѯÌõ¼þÖеÄËùÓÐʹÓÃ×ֶν¨Á¢Ë÷Òý¡£Microsoft Jet 2.0¼«ÆäÒÔºó°æ±¾µÄÊý¾Ý¿âÒýÇæ

ʹÓÃʹÓÃÁËRushmore²éѯÓÅ»¯¼¼Êõ£¬Òò´ËÖ§³ÖÒ»ÕűíµÄ¸´ºÏË÷Òý¡£

Òª¾¡Á¿±ÜÃâÔÚ²éѯÌõ¼þÖнøÐмÆËã»òÔÚ²éѯÌõ¼þÖÐʹÓÃδË÷ÒýµÄ×ֶΡ£ÅÅÐò¸üÊÇÈç´Ë£¬¾ø¶ÔÒª±ÜÃâ

¼ÆËã»òʹÓÃδË÷ÒýµÄ×ֶΡ£

Ê®¡¢Ê¹ÓÿÉÓÅ»¯µÄ±í´ïʽ

ÖØй¹Ôì²éѯÓï¾ä£¬ÒÔ±ãÓÚRushmore¼¼Êõ¿ÉÒÔ¶ÔÆä½øÐÐÓÅ»¯¡£RushmoreÊÇÒ»ÖÖÊý¾Ý·ÃÎʼ¼Êõ£¬Ê¹

ÓÃËü¿ÉÒÔÌá¸ß¼Ç¼¼¯µÄ²éѯËٶȡ£Ê¹ÓÃRushmoreµÄʱºò£¬ÈôÔÚ²éѯÌõ¼þÖÐʹÓþßÌåÀàÐ͵ıí´ï

ʽ£¬²éѯËٶȽ«·Ç³£¿ì¡£Rushmore²»»á×Ô¶¯ÎªÄãµÄ²éѯÌá¸ßËٶȣ¬Äã±ØÐë°´ÕÕ¾ßÌåµÄ·½·¨Ð޸IJé

ѯÓï¾ä£¬ÒÔ±ãÓÚRushmore¿ÉÒÔÓÅ»¯ËüÃÇ¡£

ʮһ¡¢ÓÃCOUNT(*)´úÌæ COUNT([Column Name])

Microsoft JetÊý¾Ý¿âÒýÇæÓÐÌرðµÄÓÅ»¯·½·¨£¬ËüÔÚʹÓÃCOUNT(*)Òª±ÈÓÃCOUNT([Column Name])

¿ìµÃ¶à¡£

×¢Ò⣬ÕâÁ½¸öÔËËã·ûÊÇÓвî±ðµÄ£º

Count(*) ¼ÆËãËùÓеÄÐС£ 

Count([Column Name])¼ÆËãËùÓÐColumn Name·Ç¿ÕµÄÐС£

Ê®¶þ¡¢ÔÚ±äÁ¿ÖбÜÃâʹÓÃLIKE

ÓÉÓÚÔÚ²éѯÍê³ÉµÄʱºò±äÁ¿µÄÖµ²»È·¶¨£¬ËùÒÔÎÞ·¨Ê¹ÓÃË÷Òý£¬ÕâÑù£¬½¨Á¢µÄË÷Òý¾ÍʧȥÁËÒâÒ壬Õâ

¾ÍÑÏÖØÖÆÔ¼×ŲéѯËٶȡ£

Ê®Èý¡¢±ÜÃâLIKEºÍͳÅä·ûͬʱʹÓÃ

Èç¹ûÒª°ÑLIKEÔËËã·ûͬͳÅä·ûÒ»ÆðʹÓã¬ÎªÁËʹÓÃË÷Òý£¬±ØÐë°ÑͳÅä·û·ÅÔÚºóÃæ¡£

È磬ÏÂÁÐÓï¾äÀûÓÃÁËË÷Òý¡£

  Like "Smith"

  Like "Sm*"

¶øÏÂÁÐÓï¾ä¸ù±¾Ã»ÓÐʹÓÃË÷Òý£º 

  Like "*sen"

  Like "*sen*"

Ê®ËÄ¡¢²âÊԺϲ¢Ô¼Êø

Èç¹ûÒªÔںϲ¢ÖÐʹÓñí´ïʽԼÊøÒ»¸ö×ֶεÄÊýÖµ£¬ÐèÒª²âÊÔ±í´ïʽ·ÅÔںϲ¢µÄÒ»²à£¬»¹ÊÇÆäËûµØ

·½£¬¿´ÄÄÖÖ²éѯµÄËٶȽϿ졣ÔÚһЩ²éѯÖУ¬±í´ïʽ·ÅÔںϲ¢¹Ø¼ü´ÊjoinÒ»²à·´¶ø±È½Ï¿ì¡£

Ê®Î塢ʹÓÃÖмä½á¹û±í

ÓÃSELECT INTO½¨Á¢¹¤×÷±í£¬ÓÈÆäÊǽá¹û¼¯ÓÃÓÚ¼¸¸ö²éѯµÄʱºò£¬¾¡Á¿Ê¹ÓÃÖмä½á¹û±í¡£ÔÚ²éѯǰ

×öµÄ×¼±¸¹¤×÷Ô½¶à£¬²éѯËÙ¶ÈÔ½¿ì¡£

Ê®Áù¡¢±ÜÃâ×ÓSELECTÓï¾äºÍNOT INͬʱʹÓÃ

×ÓSELECTÓï¾äºÍNOT INͬʱʹÓúÜÄÑÓÅ»¯£¬È¡·´Ç¶Ì׵IJéѯ»òOUTER JOINsÓ°ÏìºÜ´ó¡£

ÏÂÁÐÊÂÀý²éѯ²»ÔÚorders±íÖеÄÓû§£º

ÓÅ»¯Ç°£º

   SELECT Customers.*

   FROM Customers

   WHERE Customers.[Customer ID]

      NOT IN (SELECT [Customer ID] FROM Orders);

ÓÅ»¯ºó£º 

   SELECT Customers.*

   FROM Customers LEFT JOIN Orders

      ON Customers.[Customer ID] = Orders.[Customer ID]

   WHERE ((Orders.[Customer ID] Is Null));

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00158