17-2 ��Ʈw�d�ߡG��@��ƪ�

¸ê®Æ®w¥i¥HÀx¦s¤j¶qªº¸ê®Æ¡A¦ý¬O§Ú­Ì¥²¶·¯à°÷¦³¤@®M¦³®Äªº¤èªk¨Ó·j´M§Ú­Ì©Ò­nªº¸ê®Æ¡A¤~¯àµo´§¸ê®Æ®wªº³Ì¤j¥\®Ä¡C¥»¸`§Ú­Ì±N»¡©ú¦p¦ó¹ï Access ¸ê®Æ®w¶i¦æ¸ê®Æ¬d¸ß¡A¯S§OµÛ­«¸g¥Ñ¹Ï§Î¨Ï¥ÎªÌ¤¶­±¡]Graphic User Interface¡A²ºÙGUI¡^¨Ó¶i¦æ¬d¸ß¡A³o¨Ç¬d¸ß³Ì«á¥i¥HÂন¸ê®Æ®w¤§¶¡³q¥Îªºµ²ºc¤Æ¬d¸ß»y¨¥¡]²ºÙSQL¡A¸Ô¨£«á­z¡^¡A¨Ã¥i¥ÑASP¨Ó¤U¹F³o¨Ç©R¥O¡C

§Ú­ÌÁÙ¬O¥H song01.mdb ¨Ó»¡©ú¡C­º¥ý¶}±Ò¸ê®Æ®w¡A¦P®ÉÂI¿ï¡u«Ø¥ß/¬d¸ß³]­p¡v¡A¦p¤U¡G

ÂI¿ï«á¡Aµe­±¦p¤U¡G

¦¹®É«ö¡u·s¼W¡v¡A´N¥i¥H±N¸ê®Æªí¡usong¡v¥[¤J¥Ø«eªº¬d¸ß¡AµM«á«ö¡uÃö³¬¡v¡C¦pªG­n§ä¡u±i´f©f©Ò°Ûªººq¦±¡v¡A¥i¥H¤À¨â¨BÆJ¡G

  1. ¿ï¨ú¬ÛÃöÄæ¦ì¡G§Ú­Ì¥i¥HÂI¿ï¤W¥b³¡ªº¡uºq¦±¦WºÙ¡v¡AµM«á©ì©ñ¨ì¤U¥b³¡ªº²Ä¤@­ÓÄæ¦ì¡A¦AÂI¿ï¤W¥b³¡ªº¡u¥D°ÛªÌ¡v¡AµM«á©ì©ñ¨ì¤U¥b³¡ªº²Ä¤G­ÓÄæ¦ì¡C¡]©Î¬O¥i¥Hª½±µÂùÀ»¤W¥b³¡ªºÄæ¦ì§Y¥i¡C¡^
  2. ³]©wÄæ¦ì¿ï¨ú·Ç«h¡G±N¡u¥D°ÛªÌ¡vÄæ¦ìªº¡u·Ç«h¡vªÅ®æ¶ñ¤J¡u±i´f©f¡v¡C

©Ò§e²{ªºµe­±¦p¤U¡G

­Y­n°õ¦æ¬d¸ß¡A¥i¥Hª½±µÂI¿ï¤u¨ã¦CªºÅå¹Ä¸¹¡A±o¨ìµ²ªG¦p¤U¡G

«Ü©úÅã¦a¡A©Ò¦C¥X¨Óªº¸ê®Æ´N¬O±i´f©f©Ò°Ûªººq¡C·í§A­nÃö±¼³o­Ó¬d¸ßµ²ªG®É¡AAccess ·|¸ß°Ý§A¬O§_­nÀx¦s³o­Ó¬d¸ß¡A§A¥i¥H±N¥¦ª½±µÀx¦s¦¨¡u±i´f©f©Ò°Ûªººq¦±¡v¡C¤U¦¸¥u­n§AÂI¿ï³o­Ó¬d¸ß¡A¨t²Î¦ÛµM´N·|±q¸ê®Æªí¤¤¡A§ì¥X¨ÃÅã¥Ü²Å¦X¬d¸ß·Ç«hªº¸ê®Æ¡C

¨Æ¹ê¤W¡A¤@­Ó¬d¸ß¥i¥H¦³¤£¦PªºÀ˵ø¤è¦¡¡A¨Ò¦p¡G

­Y­nÅã¥Ü¡uSQLÀ˵ø¡v¡A¥u­n¦b¥´¶}¬d¸ß«á¡]¨Ï¥Î¡u³]­pÀ˵ø¡v©Î¡u¸ê®ÆªíÀ˵ø¡v¡^¡AÂI¿ï¤u¨ã¦Cªº¡uÀ˵ø¡v«ö¶s¡A¨Ã¤U©Ô¦Ü¡uSQL À˵ø¡v¡A¦p¤U¡G

³o®É­Ô Access ´N·|Åã¥Ü¹ïÀ³©ó¦¹¬d¸ßªº SQL «ü¥O¡G

Hint
Access ¥Ñ¡u³]­pÀ˵ø¡v²£¥Í SQL «ü¥O®É¡A¦³®É­Ô·|¦b¸ê®Æªí¦WºÙ©ÎÄæ¦ì¦WºÙ¥[¤W¤¤¬A©·¡A¥HÁ׶}¸ê®Æªí¦WºÙ©ÎÄæ¦ì¦WºÙ¤¤¡A¥i¯à¥X²{ªºªÅ¥Õ©Î¨ä¥¦¯S®í¦r¤¸¡C

¦b¨Ï¥Î ASP »P¸ê®Æ®w¶i¦æ¾ã¦X®É¡A¹ï¸ê®Æ®wªº³B²z³£¥²¶·­Ê¿à SQL «ü¥O¡A¦]¦¹§A¥i¥H¥ý¥Î¡u³]­pÀ˵ø¡v²£¥Í§A­nªº¬d¸ß¡A¦A±N¦¹¬d¸ßÂà´«¦¨ SQL «ü¥O¡A´NÀ³¸Ó¥i¥Hª½±µ¶K¨ì ASP ªºµ{¦¡½X¸Ì­±¤F¡I¦³Ãö©ó SQL «ü¥Oªº¥Îªk¡A¥»¸`¥u¦³Â²²¤¤¶²Ð¡A¤U¤@³¹±N¦³§ó§¹¾ãªº»¡©ú¡C

SQL «ü¥Oªº»yªk«ÜÃþ¦ü­^¤å¦ÛµM»y¨¥¡A¤£»Ý¦h°µ»¡©ú¡A¥H¤U§Ú­Ì±NÁ|´X­Ó½d¨Ò¨Ó®i¥Ü¦p¦ó¥Ñ¡u³]­pÀ˵ø¡v¨Ó²£¥ÍSQL«ü¥O¡C

­Y­n¬d¸ß¡u±i´f©f©Ò°Ûªººq¡]¨Ì¦~¥N¥Ñªñ¦Ó»·±Æ§Ç¡^¡v¡A«h¥i¥H¦b¬d¸ß¥[¤J¡u¦~¥÷¡vÄæ¦ì«á¡A¨ÃÂI¿ï¡u±Æ§Ç¡v¡A¤U©Ô¿ï¾Ü¡u»¼´î¡v¡Aµe­±¦p¤U¡G

¦¹®É¥u­n¦AÂI¿ï¤u¨ã¦CªºÅå¹Ä¸¹¡A´N·|Åã¥Ü¬d¸ßµ²ªG¡C

­Y­n¬d¸ß¡u±i´f©f¦b 1998 ¦~©Ò°Ûªººq¡v¡A«h¥i¥H¦b¡u¦~¥÷¡vÄæ¦ì·s¼W·Ç«h¡Aµe­±¦p¤U¡G

¬Û¹ïÀ³ªº SQL «ü¥O¦p¤U¡G

SELECT song.ºq¦±¦WºÙ, song.¥D°ÛªÌ, song.¦~¥÷ FROM song WHERE (((song.¥D°ÛªÌ)="±i´f©f") AND ((song.¦~¥÷)=1998));

¥H¤Wªº¬d¸ß±ø¥ó³£¬O¥H¡u¥B¡v¬°¥D¡A­Y­n¬Ý¬Ý¡u©Î¡vªº½d¨Ò¡A¦Ò¼{¤U¦C¬d¸ß¡G¡u2002¦~ªººq¦±©Î¬O¥Ñ±i´f©f¥D°Ûªººq¦±¡v¡A¬d¸ßµe­±¦p¤U¡G

´«¥y¸Ü»¡¡A¦pªG¦³¼Æ­Ó±ø¥ó¥²¶·¦P®É¦¨¥ß¡]¡u¥B¡v¡AAnd¡^¡A§Ú­Ì´N­n±N¤ñ¹ï¦r¦ê©Î¼Æ­È©ñ¦b¡u·Ç«h¡vªº¦P¤@¦C¡C¦pªG³o¨Ç±ø¥ó¥u­n¤@­Ó¦¨¥ß§Y¥i¡]¡u©Î¡v¡AOr¡^¡A§Ú­Ì´N­n±N³o¨Ç±ø¥ó©ñ¦b¡u·Ç«h¡v¥H¤Uªº¤£¦P¦C¡C¥H Access ªº¹Ï§Î¨Ï¥ÎªÌ¤¶­±¨Ó¶i¦æ¬d¸ß¡A¥u¯à¥Î©ó·í©Ò¦³ªº¤ñ¹ï±ø¥ó³£¬O¡u¥B¡v©Î³£¬O¡u©Î¡vªº±¡ªp¡A­Y¦³¸û½ÆÂøªºÅÞ¿è§PÂ_¦¡¡A´N¥²¶·¾a SQL «ü¥O¨Ó¹F¦¨¡C

¦b¤W­z¬d¸ß¤¤¡A¬Û¹ïÀ³ªº SQL «ü¥O¦p¤U¡G

SELECT song.ºq¦±¦WºÙ, song.¥D°ÛªÌ, song.¦~¥÷ FROM song WHERE (((song.¥D°ÛªÌ)="±i´f©f")) OR (((song.¦~¥÷)=2002));

­Y­n¬d¸ß¡uºq¬P¦Cªí¡v¡A¥i¥H¨Ï¥Î·Æ¹«¥kÁäÂI¿ï¡u·Ç«h¡v«á¡A¿ï¨ú¡u¦X­p¡v¥\¯à¡A¦p¤U¡G

¦¹®É·|¦b¬d¸ßµe­±¦h¤@­Ó¦WºÙ¬°¡u¦X­p¡v¾î¦C¡A¨ä¤º®e¬°¡u¸s²Õ¡v¡A¦¹¥\¯à¥i¥H±N¬Û¦Pªº¬ö¿ý¥ý±Æ§Ç«á¡A¦A±N¬Û¦Pªº¼Æµ§¬ö¿ý¦X¨Ö¦¨¤@µ§¡A¬d¸ßµe­±¦p¤U¡G

°õ¦æ¬d¸ß«á¡Aµ²ªG¦p¤U¡G

¦]¬°¨Ï¥Î¡u¸s²Õ¡v¥\¯à¡A©Ò¥H¤W­zµ²ªG¬O¤w¸g±Æ§Ç¹Lªºµ²ªG¡C¬Û¹ïÀ³ªº SQL «ü¥O¦p¤U¡G

SELECT song.¥D°ÛªÌ FROM song GROUP BY song.¥D°ÛªÌ;

¨ä¤¤ªº "GROUP BY" ´N¬O¡u¸s²Õ¡v¥\¯à¡A¥i¥H±N¬Û¦Pªº¼Æµ§¬ö¿ý¦X¨Ö¦¨¤@µ§¡C¥t¤@­Ó¥\¯à¬Û¦Pªº SQL «ü¥O¦p¤U¡G

SELECT DISTINCT song.¥D°ÛªÌ FROM song;

¦¹¬d¸ß¥i±o¨ì¬Û¦Pµ²ªG¡A¦ý¬O«oµLªk¥Ñ¡u³]­pÀ˵ø¡v¬Ý¨ì DISTINCT ªº¥\¯à¡A¥u¯à¥Ñ¡uSQLÀ˵ø¡v¨Ó«ü©w¤§¡C

¦pªG¬O­n¬d¸ß¡uºq¦±Á`¼Æ¡v¡A¥i¥H¦b²£¥Í¡u¦X­p¡v¾î¦C«á¡A±N·Æ¹«µJÂI²¾¨ì¡u¸s²Õ¡v¡A´N¥i¥HÅã¥Ü¤U©Ô¿ï³æªº«ö¶s¡A«ö¤U«á¡A½Ð¿ï¾Ü¡uµ§¼Æ¡v¡A¦p¤U¡G

°õ¦æ¬d¸ß«á¡Aµ²ªG¦p¤U¡G

¥Nªí¸ê®Æªí¤¤¦@¦³ 11 µ§¸ê®Æ¡C¬Û¹ïÀ³ªº SQL «ü¥O¦p¤U¡G

SELECT Count(song.ºq¦±¦WºÙ) AS ºq¦±¦WºÙ¤§µ§¼Æ FROM song;

¦b³]­p¬d¸ß®É¡A¡u³]­pÀ˵ø¡vÁöµM«Ü¦n¥Î¡A¦ý¦³®É­Ô¤]·|µo¥Í¡u«ü©w¤£©P¸Ô¡vªº¿ù»~¡A¦¹®ÉÁÙ±o¾a¡uSQLÀ˵ø¡v¨Ó¸É±j¡C¨Ò¦p¡A¦pªG­n¬d¡u±i´f©f©Ò°Ûºq¦±ªºÁ`¼Æ¡v¡A¤@¯ëª½Ä±ªº°µªk¬O±N¡u¥D°ÛªÌ¡vªº¡u·Ç«h¡v³]©w¦¨¡u±i´f©f¡v¡A¨Ã¿ï¨ú¡u¦X­p¡vªº¡u¸s²Õ¡v¥\¯à¡A¦p¤U¡G

¥i¬O·í§A°õ¦æ¬d¸ß®É¡A·|²£¥Í¡u·Ç«h¹Bºâ¦¡ªº¸ê®ÆÃþ«¬¤£²Å¦X¡vªº¿ù»~°T®§¡A­Y¿ï¥Î¡uSQLÀ˵ø¡v¡A¥i¬Ý¨ì¬Û¹ïÀ³ªº SQL «ü¥O¡A¦p¤U¡G SELECT Count(song.¥D°ÛªÌ) AS ¥D°ÛªÌ¤§µ§¼Æ FROM song HAVING (((Count(song.¥D°ÛªÌ))="±i´f©f"));

«Ü©úÅ㪺¡A¿ù»~µo¥Í¦b³Ì«á¤@¦Cªº±ø¥ó¡A¦]¬° Count ¬O¤@­Ó¨ç¼Æ¡A¥u¯à¥Î¨Ó­pºâ¸ê®Æªºµ§¼Æ¡A©Ò¥H§Ú­Ì¥i¥H¥Î¤â°Ê§ï¦¨¡G

SELECT Count(song.¥D°ÛªÌ) AS ¥D°ÛªÌ¤§µ§¼Æ FROM song HAVING (((song.¥D°ÛªÌ)="±i´f©f"));

µM«á¦A¿ï¥Î¡u³]­pÀ˵ø¡v¡A±o¨ìªºµe­±¦p¤U¡G

Hint
¤W­zªº¡u³]­pÀ˵ø¡vµe­±¨Æ¹ê¤W¦³ÂI¶Ã¡A¦Ó¥B¤£®e©öÀ´¡A³o¤]Åã¥Ü¦³¤@¨Ç²³æªº¬d¸ß¥i¯àÁÙ¬O¥Î SQL ©R¥O³Ì¾A¦X¡A­Y­n¥Î²³æ©öÀ´ªº¹Ï§Î¤¶­±¨Óªí¥Ü¡A¤Ï¦Ó¦³§xÃø¡C

¬d¸ßµ²ªG¦p¤U¡G

­Y­n¬d¸ß¡u¨C¤@¦ìºq¤â°Û¹Lªººq¦±¼Æ¥Ø¡v¡A«h¥i¥H¦b¡u¥D°ÛªÌ¡vÄæ¦ì¿ï¨ú¡u¦X­p/¸s²Õ¡v¡AµM«á¦b¡uºq¦±¦WºÙ¡vÄæ¦ì¿ï¨ú¡u¦X­p/µ§¼Æ¡v¡A³]­pÀ˵øªºµe­±¦p¤U¡G

­Y¿ï¥Î¡uSQLÀ˵ø¡v¡A¥i¬Ý¨ì¬Û¹ïÀ³ªº SQL «ü¥O¡A¦p¤U¡G SELECT song.¥D°ÛªÌ, Count(song.ºq¦±¦WºÙ) AS ºq¦±¦WºÙ¤§µ§¼Æ FROM song GROUP BY song.¥D°ÛªÌ; ¬d¸ßµ²ªG¦p¤U¡G

Hint
¨Æ¹ê¤W¡A¦b¤W­z½d¨Ò¤¤¡A²Ä¤G­ÓÄæ¦ì¥u¬O¥Î¨Ó­p¼Æ¡A©Ò¥H¥i¥H¥ô·N¿ï¡A¤£¥²¤@©w¬O¡uºq¦±¦WºÙ¡v¡A¤]¥i¥H±o¨ì¦P¼Ëªºµ²ªG¡C

¥»¤p¸`¥u¦³»¡©ú¹ï³æ¤@¸ê®Æªíªº¬d¸ß¡A¤U¤@¤p¸`±N»¡©ú¨â­Ó¸ê®Æªí¤§¶¡¥i¯à²£¥ÍªºÃöÁp©Ê¡C


JScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©ó¦øªA¾¹ºÝªº ASP Àô¹Ò