亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch07.htm

?? Learn SQL in an easy way...
?? HTM
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>		<TITLE>Teach Yourself SQL in 21 Days, Second Edition -- Ch 7 -- Subqueries: The Embedded SELECT Statement</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../buttonart/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself SQL in 21 Days, Second Edition</FONT></H1></CENTER><CENTER><P><A HREF="../ch06/ch06.htm"><IMG SRC="../buttonart/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../wk1rev/wk1rev.htm"><IMGSRC="../buttonart/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../buttonart/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1><FONT COLOR="#000077">- Day 7 -<BR>Subqueries: The Embedded SELECT Statement</FONT></H1></CENTER><H2><FONT COLOR="#000077">Objectives</FONT></H2><P>A subquery is a query whose results are passed as the argument for another query.Subqueries enable you to bind several queries together. By the end of the day, youwill understand and be able to do the following:<UL>	<LI>Build a subquery	<P>	<LI>Use the keywords <TT>EXISTS</TT>, <TT>ANY</TT>, and <TT>ALL</TT> with your subqueries	<P>	<LI>Build and use correlated subqueries</UL><BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>The examples for today's lesson	were created using Borland's ISQL, the same implementation used on Day 6, &quot;Joining	Tables.&quot; Remember, this implementation does not use the SQL&gt; prompt or line	numbers. <HR></BLOCKQUOTE><H2><FONT COLOR="#000077">Building a Subquery</FONT></H2><P>Simply put, a subquery lets you tie the result set of one query to another. Thegeneral syntax is as follows:</P><H5>SYNTAX:</H5><PRE><FONT COLOR="#0066FF">SELECT *FROM TABLE1WHERE TABLE1.SOMECOLUMN =(SELECT SOMEOTHERCOLUMNFROM TABLE2WHERE SOMEOTHERCOLUMN = SOMEVALUE)</FONT></PRE><P>Notice how the second query is nested inside the first. Here's a real-world examplethat uses the <TT>PART</TT> and <TT>ORDERS</TT> tables:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT *FROM PART</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">    PARTNUM DESCRIPTION                PRICE=========== ==================== ===========         54 PEDALS                     54.25         42 SEATS                      24.50         46 TIRES                      15.25         23 MOUNTAIN BIKE             350.45         76 ROAD BIKE                 530.00         10 TANDEM                   1200.00</FONT></PRE><H5><FONT COLOR="#000000">INPUT/OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF"><B>SELECT *FROM ORDERS</B>  ORDEREDON NAME           PARTNUM    QUANTITY REMARKS=========== ========== =========== =========== ========15-MAY-1996 TRUE WHEEL          23           6 PAID19-MAY-1996 TRUE WHEEL          76           3 PAID 2-SEP-1996 TRUE WHEEL          10           1 PAID30-JUN-1996 TRUE WHEEL          42           8 PAID30-JUN-1996 BIKE SPEC           54          10 PAID30-MAY-1996 BIKE SPEC           10           2 PAID30-MAY-1996 BIKE SPEC           23           8 PAID17-JAN-1996 BIKE SPEC           76          11 PAID17-JAN-1996 LE SHOPPE           76           5 PAID 1-JUN-1996 LE SHOPPE           10           3 PAID 1-JUN-1996 AAA BIKE            10           1 PAID 1-JUL-1996 AAA BIKE            76           4 PAID 1-JUL-1996 AAA BIKE            46          14 PAID11-JUL-1996 JACKS BIKE          76          14 PAID</FONT></PRE><H5>ANALYSIS:</H5><P>The tables share a common field called <TT>PARTNUM</TT>. Suppose that you didn'tknow (or didn't want to know) the <TT>PARTNUM</TT>, but instead wanted to work withthe description of the part. Using a subquery, you could type this:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT *FROM ORDERSWHERE PARTNUM =(SELECT PARTNUMFROM PARTWHERE DESCRIPTION LIKE &quot;ROAD%&quot;)</B>  ORDEREDON NAME           PARTNUM    QUANTITY REMARKS=========== ========== =========== =========== ========19-MAY-1996 TRUE WHEEL          76           3 PAID17-JAN-1996 BIKE SPEC           76          11 PAID17-JAN-1996 LE SHOPPE           76           5 PAID 1-JUL-1996 AAA BIKE            76           4 PAID11-JUL-1996 JACKS BIKE          76          14 PAID</FONT></PRE><H5>ANALYSIS:</H5><P>Even better, if you use the concepts you learned on Day 6, you could enhance the<TT>PARTNUM</TT> column in the result by including the <TT>DESCRIPTION</TT>, making<TT>PARTNUM</TT> clearer for anyone who hasn't memorized it. Try this:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT O.ORDEREDON, O.PARTNUM,P.DESCRIPTION, O.QUANTITY, O.REMARKSFROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUMANDO.PARTNUM =(SELECT PARTNUMFROM PARTWHERE DESCRIPTION LIKE &quot;ROAD%&quot;)</B>  ORDEREDON     PARTNUM DESCRIPTION       QUANTITY REMARKS=========== =========== ============ =========== =========19-MAY-1996          76 ROAD BIKE                3 PAID 1-JUL-1996          76 ROAD BIKE                4 PAID17-JAN-1996          76 ROAD BIKE                5 PAID17-JAN-1996          76 ROAD BIKE               11 PAID11-JUL-1996          76 ROAD BIKE               14 PAID</FONT></PRE><H5>ANALYSIS:</H5><P>The first part of the query is very familiar:</P><PRE><FONT COLOR="#0066FF">SELECT O.ORDEREDON, O.PARTNUM,P.DESCRIPTION, O.QUANTITY, O.REMARKSFROM ORDERS O, PART P</FONT></PRE><P>Here you are using the aliases <TT>O</TT> and <TT>P</TT> for tables <TT>ORDERS</TT>and <TT>PART</TT> to select the five columns you are interested in. In this casethe aliases were not necessary because each of the columns you asked to return isunique. However, it is easier to make a readable query now than to have to figureit out later. The first <TT>WHERE</TT> clause you encounter</P><PRE><FONT COLOR="#0066FF">WHERE O.PARTNUM = P.PARTNUM</FONT></PRE><P>is standard language for the join of tables <TT>PART</TT> and <TT>ORDERS</TT>specified in the <TT>FROM</TT> clause. If you didn't use this <TT>WHERE</TT> clause,you would have all the possible row combinations of the two tables. The next sectionincludes the subquery. The statement</P><PRE><FONT COLOR="#0066FF">ANDO.PARTNUM =(SELECT PARTNUMFROM PARTWHERE DESCRIPTION LIKE &quot;ROAD%&quot;)</FONT></PRE><P>adds the qualification that <TT>O.PARTNUM</TT> must be equal to the result ofyour simple subquery. The subquery is straightforward, finding all the part numbersthat are <TT>LIKE &quot;ROAD%&quot;</TT>. The use of <TT>LIKE</TT> was somewhat lazy,saving you the keystrokes required to type <TT>ROAD BIKE</TT>. However, it turnsout you were lucky this time. What if someone in the Parts department had added anew part called <TT>ROADKILL</TT>? The revised <TT>PART</TT> table would look likethis:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT *FROM PART</B>    PARTNUM DESCRIPTION                PRICE=========== ==================== ===========         54 PEDALS                     54.25         42 SEATS                      24.50         46 TIRES                      15.25         23 MOUNTAIN BIKE             350.45         76 ROAD BIKE                 530.00         10 TANDEM                   1200.00         77 ROADKILL                    7.99</FONT></PRE><P>Suppose you are blissfully unaware of this change and try your query after thisnew product was added. If you enter this:</P><PRE><FONT COLOR="#0066FF"><B>SELECT O.ORDEREDON, O.PARTNUM,P.DESCRIPTION, O.QUANTITY, O.REMARKSFROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUMANDO.PARTNUM =(SELECT PARTNUMFROM PARTWHERE DESCRIPTION LIKE &quot;ROAD%&quot;)</B></FONT></PRE><P>the SQL engine complains</P><PRE><FONT COLOR="#0066FF">multiple rows in singleton select</FONT></PRE><P>and you don't get any results. The response from your SQL engine may vary, butit still complains and returns nothing.</P><P>To find out why you get this undesirable result, assume the role of the SQL engine.You will probably evaluate the subquery first. You would return this:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT PARTNUMFROM PARTWHERE DESCRIPTION LIKE &quot;ROAD%&quot;</B>    PARTNUM===========         76         77</FONT></PRE><P>You would take this result and apply it to <TT>O.PARTNUM =</TT>, which is thestep that causes the problem.</P><H5>ANALYSIS:</H5><P>How can <TT>PARTNUM</TT> be equal to both <TT>76</TT> and <TT>77</TT>? This mustbe what the engine meant when it accused you of being a simpleton. When you usedthe <TT>LIKE</TT> clause, you opened yourself up for this error. When you combinethe results of a relational operator with another relational operator, such as <TT>=</TT>,<TT>&lt;</TT>, or <TT>&gt;</TT>, you need to make sure the result is singular. Inthe case of the example we have been using, the solution would be to rewrite thequery using an <TT>=</TT> instead of the <TT>LIKE</TT>, like this:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT O.ORDEREDON, O.PARTNUM,P.DESCRIPTION, O.QUANTITY, O.REMARKSFROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUMANDO.PARTNUM =(SELECT PARTNUMFROM PARTWHERE DESCRIPTION = &quot;ROAD BIKE&quot;)</B>  ORDEREDON     PARTNUM DESCRIPTION        QUANTITY REMARKS=========== =========== =============== =========== ==========19-MAY-1996          76 ROAD BIKE                 3 PAID 1-JUL-1996          76 ROAD BIKE                 4 PAID17-JAN-1996          76 ROAD BIKE                 5 PAID17-JAN-1996          76 ROAD BIKE                11 PAID11-JUL-1996          76 ROAD BIKE                14 PAID</FONT></PRE><H5>ANALYSIS:</H5><P>This subquery returns only one unique result; therefore narrowing your <TT>=</TT>condition to a single value. How can you be sure the subquery won't return multiplevalues if you are looking for only one value?</P><P>Avoiding the use of <TT>LIKE</TT> is a start. Another approach is to ensure theuniqueness of the search field during table design. If you are the untrusting type,you could use the method (described yesterday) for joining a table to itself to checka given field for uniqueness. If you design the table yourself (see Day 9, &quot;Creatingand Maintaining Tables&quot;) or trust the person who designed the table, you couldrequire the column you are searching to have a unique value. You could also use apart of SQL that returns only one answer: the aggregate function.<H2><FONT COLOR="#000077">Using Aggregate Functions with Subqueries</FONT></H2><P>The aggregate functions <TT>SUM</TT>, <TT>COUNT</TT>, <TT>MIN</TT>, <TT>MAX</TT>,and <TT>AVG</TT> all return a single value. To find the average amount of an order,type this:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT AVG(O.QUANTITY * P.PRICE)FROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUM</B></FONT></PRE><H5><FONT COLOR="#000000"><B>OUTPUT:</B></FONT></H5><PRE><FONT COLOR="#000000"><B></B></FONT></PRE><PRE><FONT COLOR="#0066FF">        AVG===========    2419.16</FONT></PRE><H5>ANALYSIS:</H5><P>This statement returns only one value. To find out which orders were above average,use the preceding <TT>SELECT</TT> statement for your subquery. The complete queryand result are as follows:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT O.NAME, O.ORDEREDON,O.QUANTITY * P.PRICE TOTALFROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUMANDO.QUANTITY * P.PRICE  &gt;(SELECT AVG(O.QUANTITY * P.PRICE)FROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUM)</B>NAME         ORDEREDON       TOTAL========== =========== ===========LE SHOPPE   1-JUN-1996     3600.00BIKE SPEC  30-MAY-1996     2803.60LE SHOPPE  17-JAN-1996     2650.00BIKE SPEC  17-JAN-1996     5830.00JACKS BIKE 11-JUL-1996     7420.00</FONT></PRE><H5>ANALYSIS:</H5><P>This example contains a rather unremarkable <TT>SELECT/FROM/WHERE</TT> clause:</P><PRE><FONT COLOR="#0066FF">SELECT O.NAME, O.ORDEREDON,O.QUANTITY * P.PRICE TOTALFROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUM</FONT></PRE><P>These lines represent the common way of joining these two tables. This join isnecessary because the price is in <TT>PART</TT> and the quantity is in <TT>ORDERS</TT>.The <TT>WHERE</TT> ensures that you examine only the join-formed rows that are related.You then add the subquery:</P><PRE><FONT COLOR="#0066FF">ANDO.QUANTITY * P.PRICE  &gt;(SELECT AVG(O.QUANTITY * P.PRICE)FROM ORDERS O, PART PWHERE O.PARTNUM = P.PARTNUM)</FONT></PRE><P>The preceding condition compares the total of each order with the average youcomputed in the subquery. Note that the join in the subquery is required for thesame reasons as in the main <TT>SELECT</TT> statement. This join is also constructedexactly the same way. There are no secret handshakes in subqueries; they have exactlythe same syntax as a standalone query. In fact, most subqueries start out as standalonequeries and are incorporated as subqueries after their results are tested.<H2><FONT COLOR="#000077">Nested Subqueries</FONT></H2><P>Nesting is the act of embedding a subquery within another subquery. For example:</P><PRE><FONT COLOR="#0066FF">Select * FROM SOMETHING WHERE ( SUBQUERY(SUBQUERY(SUBQUERY)));</FONT></PRE><P>Subqueries can be nested as deeply as your implementation of SQL allows. For example,to send out special notices to customers who spend more than the average amount ofmoney, you would combine the information in the table <TT>CUSTOMER</TT></P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT *FROM CUSTOMER</B></FONT></PRE><H5><FONT COLOR="#000000"><B>OUTPUT:</B></FONT></H5><PRE><FONT COLOR="#000000"><B></B></FONT></PRE><PRE><FONT COLOR="#0066FF">NAME       ADDRESS    STATE  ZIP        PHONE       REMARKS========== ========== ====== ========== =========== ==========TRUE WHEEL 55O HUSKER NE     58702      555-4545    NONEBIKE SPEC  CPT SHRIVE LA     45678      555-1234    NONE

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品精品亚洲| 久久电影网站中文字幕 | 精品一区二区三区久久久| 亚洲一区视频在线观看视频| 亚洲精品日日夜夜| 一区二区三区电影在线播| 17c精品麻豆一区二区免费| 最新热久久免费视频| 国产三级精品在线| 不卡一区二区在线| 另类小说视频一区二区| 久久精品国产网站| 国产真实乱对白精彩久久| 久久国产三级精品| 国产成人综合亚洲91猫咪| 欧美三级中文字| 成人福利视频在线看| 亚洲午夜精品一区二区三区他趣| 亚洲一区在线免费观看| 日韩成人午夜精品| 国产一区二区三区久久悠悠色av | heyzo一本久久综合| 99久久精品国产导航| 色老头久久综合| 欧美精品日韩一本| 26uuu色噜噜精品一区二区| 国产嫩草影院久久久久| 成人欧美一区二区三区黑人麻豆| 亚洲一区在线视频观看| 美女免费视频一区| 国产91清纯白嫩初高中在线观看 | caoporn国产精品| 91丨porny丨国产| 欧美日韩一级黄| 亚洲精品一区二区三区福利| 国产精品久久久久天堂| 亚洲综合成人在线| 九九九精品视频| 欧美激情在线免费观看| 精品日韩欧美在线| 国产女人18毛片水真多成人如厕| 亚洲三级小视频| 美国欧美日韩国产在线播放| 成人高清免费观看| 欧美一区二区三区男人的天堂| 久久久久久久网| 亚洲午夜在线观看视频在线| 国产最新精品精品你懂的| 91国偷自产一区二区开放时间 | 国产精品一区专区| 色偷偷久久人人79超碰人人澡| 日韩一区二区在线看| 国产精品久久精品日日| 天堂久久一区二区三区| 粉嫩13p一区二区三区| 欧美日韩电影在线播放| 欧美激情综合五月色丁香小说| 香蕉乱码成人久久天堂爱免费| 国产九色精品成人porny| 欧美婷婷六月丁香综合色| 国产日韩欧美精品综合| 亚洲超碰97人人做人人爱| 成人三级伦理片| 欧美成人精品1314www| 亚洲精品国久久99热| 国产麻豆视频一区二区| 91精品国产色综合久久久蜜香臀| 成人欧美一区二区三区黑人麻豆| 老司机免费视频一区二区| 91福利视频在线| 中文字幕欧美日韩一区| 看片网站欧美日韩| 欧美日韩在线电影| 亚洲另类中文字| 成人黄色软件下载| 精品国产人成亚洲区| 亚洲v精品v日韩v欧美v专区| 97se狠狠狠综合亚洲狠狠| 精品国产一区二区三区久久影院 | 亚洲一二三区不卡| a在线欧美一区| 国产婷婷色一区二区三区四区| 日韩电影在线免费观看| 欧美亚洲高清一区| 亚洲欧美日韩在线不卡| 丰满放荡岳乱妇91ww| 久久先锋影音av| 久久精品国产秦先生| 91精品国产综合久久婷婷香蕉| 一区二区三区四区国产精品| 99久免费精品视频在线观看 | 国产一区二区中文字幕| 91麻豆精品国产自产在线| 亚洲午夜av在线| 欧美日韩午夜在线| 亚洲午夜电影在线| 欧美日韩情趣电影| 亚洲成人在线免费| 欧美午夜寂寞影院| 婷婷久久综合九色国产成人 | 久久久高清一区二区三区| 韩国成人福利片在线播放| 26uuu成人网一区二区三区| 国产资源精品在线观看| 久久久久久综合| 国产不卡视频在线观看| 亚洲成人黄色影院| 91精品1区2区| 亚洲18色成人| 51精品久久久久久久蜜臀| 日日夜夜免费精品| 日韩视频一区二区| 韩国一区二区三区| 日本一区二区免费在线| a美女胸又www黄视频久久| 亚洲美腿欧美偷拍| 欧美性一二三区| 美女网站一区二区| 国产亚洲人成网站| 不卡的av电影| 亚洲一区精品在线| 337p亚洲精品色噜噜噜| 久久精品国产精品亚洲精品 | 老汉av免费一区二区三区| 久久夜色精品国产欧美乱极品| 国产黄色91视频| 国产精品护士白丝一区av| 色综合久久中文综合久久牛| 亚洲国产另类精品专区| 精品欧美一区二区三区精品久久 | 国产成人免费高清| 1024成人网色www| 欧美日韩在线播放三区四区| 麻豆freexxxx性91精品| 国产片一区二区| 91久久线看在观草草青青 | 欧美丰满少妇xxxxx高潮对白| 老司机精品视频在线| 国产精品国产自产拍高清av王其| 91高清视频在线| 美女一区二区视频| 中文av字幕一区| 777色狠狠一区二区三区| 国产不卡在线一区| 亚洲成人激情自拍| 亚洲国产精品av| 欧美日韩精品一区二区在线播放| 国内精品自线一区二区三区视频| 中文字幕一区日韩精品欧美| 欧美一区日韩一区| 不卡的av网站| 久久精品国产一区二区| 亚洲欧美日韩中文字幕一区二区三区| 欧美一区二区三区免费大片| 成人午夜在线视频| 日韩激情视频在线观看| 国产精品久久久一本精品| 3atv一区二区三区| 91蜜桃在线免费视频| 久久精品72免费观看| 亚洲精品写真福利| 久久香蕉国产线看观看99| 欧美日韩精品系列| 99久久精品久久久久久清纯| 蜜桃精品在线观看| 一区二区三区在线播放| 久久新电视剧免费观看| 7777精品伊人久久久大香线蕉| 白白色亚洲国产精品| 久久99蜜桃精品| 亚洲3atv精品一区二区三区| 国产精品传媒在线| 欧美精品一区二区三区一线天视频| 在线一区二区三区四区五区| 国产成人aaa| 经典三级一区二区| 日韩av一区二区在线影视| 1000部国产精品成人观看| 26uuu国产电影一区二区| 欧美精品1区2区| 在线观看一区二区视频| 国产suv精品一区二区883| 久久国产精品无码网站| 天天色综合天天| 亚洲人成网站影音先锋播放| 国产婷婷一区二区| 精品国产一二三| 日韩无一区二区| 在线播放欧美女士性生活| 欧美亚洲综合久久| 91福利区一区二区三区| av资源网一区| 丁香另类激情小说| 国产美女av一区二区三区| 精品一区二区三区欧美| 日本在线不卡一区| 天堂在线一区二区| 午夜精品免费在线观看| 一区二区三区四区激情| 亚洲自拍偷拍九九九|