|
- ¼±Åà Äõ¸®
|
¸Å°³º¯¼ö ¸Å°³º¯¼ö´Â µÉ ¼ö ÀÖÀ¸¸é ¹Ì¸® Á¤ÀǸ¦ ÇÑ ´ÙÀ½ »ç¿ëÇϽʽÿÀ. ¸Å°³º¯¼ö¸¦ Á¤ÀÇÇÏ·Á¸é ¸Þ´º¿¡¼ [Äõ¸®]-[¸Å°³º¯¼ö¡¦]¸¦ ½ÇÇàÇÏ¸é µ¥ÀÌÅÍ Çü½Ä±îÁö Á¤ÀǸ¦ ÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×·¯³ª ¸Å°³º¯¼ö¸¦ ¸í½ÃÀûÀ¸·Î Á¤ÀÇÇÏÁö ¾Ê¾Ò´õ¶óµµ Äõ¸®¿¡ ¾ø´Â À̸§(Çʵå¸í)À» »ç¿ëÇϸé Äõ¸®´Â ¸Å°³º¯¼ö¶ó ¿©±â°í ó¸®ÇÕ´Ï´Ù. ´Ü, Å©·Î½ºÅÇ ÁúÀÇ¿¡¼´Â ¹Ýµå½Ã ¸Å°³º¯¼ö¸¦ ¸í½ÃÀûÀ¸·Î Á¤ÀÇÇÑ ´ÙÀ½¿¡ »ç¿ëÇÏ¼Å¾ß ÇÕ´Ï´Ù. |
PARAMETERS ½ÃÀÛÀÏ DateTime, Á¾·áÀÏ DateTime;
SELECT Employees.Country, Employees.LastName, Employees.FirstName,
Orders.ShippedDate,
Orders.OrderID, [Order Subtotals].Subtotal AS
SaleAmount
FROM Employees INNER JOIN (Orders INNER JOIN [Order Subtotals] ON
Orders.OrderID = [Order Subtotals].OrderID) ON Employees.EmployeeID =
Orders.EmployeeID
WHERE (((Orders.ShippedDate) Between [½ÃÀÛÀÏ] And [Á¾·áÀÏ]));
Å©·Î½ºÅÇ Äõ¸®¸¦ »ç¿ëÇÏ¸é µ¥ÀÌÅ͸¦ °è»êÇÏ°í À籸¼ºÇÒ ¼ö ÀÖÀ¸¹Ç·Î µ¥ÀÌÅ͸¦ ½±°Ô ºÐ¼®ÇÒ ¼ö ÀÖ½À´Ï´Ù. Å©·Î½ºÅÇ Äõ¸®´Â µ¥ÀÌÅͽÃÆ®ÀÇ ¿ÞÂÊ¿¡ ÀÖ´Â Á¤º¸¸¦ ¼¼·Î·Î ±×·ìÈÇϰųª ¸Ç À§¿¡ ÀÖ´Â Á¤º¸¸¦ °¡·Î·Î ±×·ìÈÇÑ µ¥ÀÌÅÍ¿¡ ´ëÇØ ÇÕ°è, Æò±Õ, °³¼ö, ±âŸ ¿ä¾à µîÀ» °è»êÇÕ´Ï´Ù.
¿ä¾àÁúÀÇ¿Í ºñ½ÁÇÏÁö¸¸ Å©·Î½ºÅÇÀ̶õ ±×¸®µå°¡ Çϳª ´õ »ý°å½À´Ï´Ù. Å©·Î½ºÅÇ¿¡´Â Çà°ú ¿ ¸Ó¸®±ÛÀÌ ÀÖ°í µÎ [Çà]°ú [¿]ÀÌ ¼·Î ±³Â÷ÇÏ´Â ºÎºÐ¿¡ ÀûÀ» [¿ä¾à°ª]ÀÌ Á¸ÀçÇØ¾ß ÇÕ´Ï´Ù.
TRANSFORM Sum(CCur([Order Details].UnitPrice*[Quantity]*(1-[Discount])/100)*100)
AS ProductAmount
SELECT Products.ProductName, Orders.CustomerID, Year([OrderDate])
AS OrderYear
FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON
Orders.OrderID =
[Order Details].OrderID) ON Products.ProductID = [Order
Details].ProductID
WHERE (((Orders.OrderDate) Between #1/1/1997# And #12/31/1997#))
GROUP BY Products.ProductName, Orders.CustomerID,
Year([OrderDate])
PIVOT DatePart("q",[OrderDate],1,0) & "/4 ºÐ±â" In ("1/4 ºÐ±â","2/4
ºÐ±â","3/4 ºÐ±â","4/4 ºÐ±â");
ÁúÀÇ°è»êÇÔ¼ö³ª ±¸°£À» Á¤Çϱâ À§ÇÑ ÇÔ¼ö, ƯÈ÷ ³¯Â¥ Çʵ忡¼ ±¸°£À» Á¤Çϱâ À§ÇÑ ³¯Â¥ ÇÔ¼öµéÀÌ ¸¹ÀÌ »ç¿ëµÇ¹Ç·Î ³¯Â¥ °ü·Ã ÇÔ¼öµéÀº µµ¿ò¸»À» º¸½Ã°í ²À ÀÍÇô µÎ½Ê½Ã¿À.
ÀÌ·¸°Ô ÇÔ¼öµéÀÌ »ç¿ëµÇ´Â °Í»Ó¸¸ ¾Æ´Ï¶ó Å©·Î½ºÅÇÁúÀÇ´Â ¾²ÀÌ´Â Å°¿öµåµµ ¸¹¾Æ¼ ±¸¹®ÀÌ º¹ÀâÇÏ°Ô ´À²¸Á® Ãʺ¸ÀÚ ºÐµé¿¡°Ô´Â »ó´çÈ÷ ºÎ´ã½º·¯¿î Äõ¸®¿¡ ÇØ´çµË´Ï´Ù. Å©·Î½ºÅÇ Äõ¸® ¸¶¹ý»ç¸¦ ÀÌ¿ëÇÏ¿© ¸¸µå´Â °Íµµ Ãʺ¸ÀÚ ºÐµé¿¡°Ô´Â ±×·¸°Ô ½±Áö°¡ ¾Ê½À´Ï´Ù.
Å©·Î½ºÅÇ Äõ¸®¸¦ ¸¸µé ¶§ ´ÙÀ½°ú °°ÀÌ »ý°¢À» Á¤¸®ÇÏ°Ô µÇ¸é ¾î·ÆÁö ¾Ê½À´Ï´Ù. À§ ¿¹Á¦´Â [Á¦Ç°º°]·Î ¾î¶² [°í°´]ÀÌ [ÇØ]¸¶´Ù ¾´ ±Ý¾×À» [ºÐ±â]º°·Î ±¸ºÐÇؼ ¾Ë¾Æº¸°íÀÚ ÇÏ´Â ÁúÀǹ®ÀÔ´Ï´Ù. ÀÌ°ÍÀ» Á¤¸®Çϸé [Á¦Ç°º°]-[°í°´º°]-[¿¬µµº°]-[ºÐ±âº°]-[±¸¸Å±Ý¾×]À¸·Î µÇ°í TRNSFORM Á¦ÀÏ µÚÀÇ Ç׸ñÀÌ TRNSFORM, ±× ¾Õ¿¡ ÀÖ´Â ¼¼ºÎÁ¶°ÇÀÌ PIVOT, ±×¸®°í ³ª¸ÓÁö Á¶°ÇµéÀÌ GROUP BY¿¡ °ü·ÃµË´Ï´Ù. ÀÌ°ÍÀ» ´Ù½Ã ±¸ºÐÇغ¸¸é, ¾Ë°íÀÚ ÇÏ´Â °ªÀ» Ç×»ó ¸¶Áö¸·¿¡ ¹èÄ¡¸¦ ÇÏ°í ÀÌ ¾Õ¿¡´Â ±× ±âÁصéÀ» Àû´Âµ¥ [±âÁصé(¼ø¼´ë·Î)]-[¸¶Áö¸· ¼¼ºÎ±âÁØ]-[¿ä¾à°è»ê ÇÒ °Í] ¼ø¼·Î ¹èÄ¡ÇÕ´Ï´Ù. ÀÌ°ÍÀº [Group By]-[Pivot]-[Transform]¿¡ ÇØ´çµË´Ï´Ù. Å©·Î½ºÅÇÄõ¸® ¸¶¹ý»ç¸¦ ÀÌ¿ëÇÒ ¶§ ÀÌ ¼ø¼´ë·Î °ªÀ» ¼³Á¤ÇØ ÁÖ¸é ¿øÇÏ´Â Äõ¸®°¡ ¸¸µé¾î Áú °Ì´Ï´Ù. |
1. GROUP BY ´ÙÀ½¿¡ ³õÀÎ °ÍÀº °³º°ÀûÀÎ ·¹ÄÚµå(Çà)¸¦
±×·ìÀ¸·Î ¸¸µé¾îÁø ³»¿ëÀ¸·Î ¿©ÀüÈ÷ Çà¿¡ ³²¾Æ ÀÖ°Ô µÇ°í µû¶ó¼ Çà ¸Ó¸®±ÛÀÌ µÈ´Ù.
2. PIVOT ´ÙÀ½¿¡ ¾²¿©Áø ¼¼ºÎ Á¶°ÇÀº ¿ ¸Ó¸®±ÛÀÌ µÈ´Ù.
3. TRANSFORM ´ÙÀ½¿¡ ÁúÀÇ°è»êÇÔ¼ö¸¦ »ç¿ëÇÏ¿© °è»êÇÑ °ªÀ»
³ªÅ¸³¾ °ª Çʵå·Î Å×À̺íÀ» ä¿ì´Â °ªÀÌ µÈ´Ù.
½ÇÇà Äõ¸®´Â ¿©·¯ ·¹Äڵ带 ÇѲ¨¹ø¿¡ º¯°æÇϰųª À̵¿ÇÒ ¼ö ÀÖ´Â Äõ¸®ÀÔ´Ï´Ù. ½ÇÇà Äõ¸®¿¡´Â ³× °¡Áö À¯ÇüÀÌ ÀÖ½À´Ï´Ù. ½ÇÇà Äõ¸®´Â
µ¥ÀÌÅ͸¦ º¯°æÇϹǷΠÇ×»ó Á¶½ÉÇؼ »ç¿ëÇϵµ·Ï ÇÕ´Ï´Ù. Ãʺ¸ÀÚ ºÐµéÀº ÀÌ·± °Ô ÀÖ±¸³ª ÇÏ´Â Á¤µµ·Î¸¸ ¾Ë¾Æ µÎ½Ê½Ã¿À.
▪ »èÁ¦ Äõ¸® Å×À̺í Çϳª À̻󿡼 ·¹ÄÚµå ±×·ìÀ» »èÁ¦ÇÕ´Ï´Ù. ¿¹¸¦
µé¾î ´ÜÁ¾Á¦Ç°¸¸ ÀÏ°ý »èÁ¦ÇÒ ¼ö ÀÖ½À´Ï´Ù.
DELETE Employees.*
FROM Employees
WHERE Title = ¡°Trainee¡±;
▪ ¾÷µ¥ÀÌÆ® Äõ¸® ¾÷µ¥ÀÌÆ® Äõ¸®´Â Å×À̺í Çϳª À̻󿡼 ·¹ÄÚµå
±×·ìÀ» ÀüüÀûÀ¸·Î º¯°æÇÕ´Ï´Ù. ¿¹¸¦ µé¾î, Á¦Ç°ÀÇ °¡°ÝÀ̳ª ÀÓ±Ý µîÀ» ÀÏ°ýÇؼ 10%¾¿ ¿Ã¸®°íÀÚ ÇÏ´Â °æ¿ì¿¡ »ç¿ëµË´Ï´Ù.
UPDATE Employees
SET ReportsTo = 5
WHERE ReportsTo = 2;
▪ Ãß°¡ Äõ¸® Ãß°¡ Äõ¸®´Â Å×À̺í Çϳª À̻󿡼 ·¹ÄÚµå ±×·ìÀ»
°¡Á®´Ù Å×À̺í Çϳª ÀÌ»óÀÇ ³¡¿¡ Ãß°¡ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î, »õ °í°´µé°ú ±× °í°´µé¿¡ ´ëÇÑ µ¥ÀÌÅÍ°¡ Æ÷ÇÔµÈ Å×À̺íÀÌ ÀÖ´Â µ¥ÀÌÅͺ£À̽º°¡
»ý±ä °æ¿ì, ¸ðµç °ü·Ã Á¤º¸¸¦ µ¥ÀÌÅͺ£À̽º¿¡ ÀÏÀÏÀÌ ÀÔ·ÂÇÏ´Â ´ë½Å Customers Å×ÀÌºí¿¡ Ãß°¡Çϱ⸸ ÇÏ¸é µË´Ï´Ù.
´ÙÁß ·¹ÄÚµå Ãß°¡ Äõ¸®:
INSERT INTO Customers
SELECT *
FROM [New Customers];
´ÜÀÏ ·¹ÄÚµå Ãß°¡ Äõ¸®:
INSERT INTO Employees (FirstName,LastName,
Title)
VALUES ('Harry', 'Washington', 'Trainee');
▪ Å×ÀÌºí ¸¸µé±â Äõ¸® Å×ÀÌºí ¸¸µé±â Äõ¸®´Â Å×À̺í Çϳª
À̻󿡼 µ¥ÀÌÅÍÀÇ ÀϺγª Àüü¸¦ °¡Á®¿Í »õ Å×À̺íÀ» ¸¸µì´Ï´Ù. ÀÌ Äõ¸®´Â ´Ù¸¥ ¾×¼¼½º µ¥ÀÌÅͺ£À̽º³ª ÀÌÀü ·¹Äڵ尡 µé¾î ÀÖ´Â ±â·Ï
Å×À̺í·Î ³»º¸³¾ Å×À̺íÀ» ¸¸µé ¶§ À¯¿ëÇÕ´Ï´Ù.
SELECT Products.*
INTO ´ÜÁ¾Ç°¸ñÅ×À̺í
FROM Products
WHERE ((( Products.Discontuned) = True));
Åë°ú Äõ¸®, µ¥ÀÌÅÍ Á¤ÀÇ Äõ¸®, ÅëÇÕ Äõ¸®´Â QBE µðÀÚÀΠâÀ» ÀÌ¿ëÇÒ ¼ö ¾ø°í ¸Þ´º¿¡¼ [º¸±â]-[SQL º¸±â]·Î SQL
ÀÔ·ÂâÀ» ¿¬ ´ÙÀ½ Á÷Á¢ SQL ¹®À» ÀÛ¼ºÇØ¾ß ÇÕ´Ï´Ù.
¶Ç ÇÏÀ§ Äõ¸®´Â Äõ¸® µðÀÚÀÎ ´«±ÝÀÇ Çʵå ÇàÀ̳ª Á¶°Ç Çà¿¡ SQLÀ» ÀÔ·ÂÇÕ´Ï´Ù.
[SQL ÀÔ·Ââ º¸±â] ¾×¼¼½º Äõ¸®¸¦ µðÀÚÀκ¸±â·Î ¿¸é ±×·¡ÇÈÀÎÅÍÆäÀ̽ºÀÎ QBE µðÀÚÀΠ⸸ º¸ÀÔ´Ï´Ù. ½ÇÁ¦ ÀÛ¼ºµÈ SQL¹®À» È®ÀÎÇϽ÷Á¸é Äõ¸®¸¦ µðÀÚÀÎ º¸±â·Î ¿°í ¸Þ´º¿¡¼ [º¸±â]-[SQL º¸±â]¸¦ Ŭ¸¯ÇϽʽÿÀ.
|
Áö±Ý±îÁö ¸¹ÀÌ »ç¿ëÇÏ´Â Äõ¸®¿¡ ´ëÇØ ¼³¸íÀ» ÇÏ¿´½À´Ï´Ù. °£´ÜÇÏ°Ô ¼³¸íÀ» ÇßÁö¸¸ SQL¹®À» óÀ½ Á¢ÇϽŠºÐµé¿¡°Ô´Â »ó´çÈ÷ ¾î·Á¿î ³»¿ëÀ̾úÀ» °Ì´Ï´Ù. ±×·¸Áö¸¸ ½Ç¸ÁÇÏÁö ¸¶½Ã°í ¡®º¸°í ¶Ç º¸°í¡¯ ÇϽøé Àͼ÷ÇØÁö½Ã¸®¶ó ¹Ï½À´Ï´Ù.
¿ÀÇǽº Æ©ÅÍÀÇ ¹«·á°Á ¼½¼Ç¿¡¼ QBE(Query By Example) â¿¡¼ °¢°¢ÀÇ Äõ¸®¸¦ ¸¸µé°í Çʵ带 Ãß°¡ÇÏ°í, Á¤·ÄÇÏ°í, Á¶°Ç¿¡ µû¶ó ·¹Äڵ带 ÁúÀÇÇÏ°í, °è»êÇʵ带 ¸¸µå´Â °Í µî¿¡ ´ëÇؼ ¹Ýµå½Ã °øºÎ¸¦ ÇϽõµ·Ï ÇϽʽÿÀ. ±×¸®°í SQLâÀ» ¿¾î Ç×»ó QBE·Î ¸¸µç Äõ¸®ÀÇ ³»¿ëÀ» È®ÀÎÇÏ´Â ½À°üÀ» °¡Áö½Ã¸é SQL¹®¿¡ ´ëÇؼ´Â Á¶¸¸°£ Àͼ÷ÇØÁö½Ç °Ì´Ï´Ù.
¾×¼¼½º2000 ¹«·á°Á :
www.officetutor.co.kr/tutor_new/access/daily/index.asp
¡¡
|
||||
¡¡ |