文件名称:连接多个表-SQL语言基础
文件大小:5.26MB
文件格式:PPT
更新时间:2024-05-15 13:24:57
SQL 基础
连接多个表 * NAME CUSTID ----------- ------ JOCKSPORTS 100 TKB SPORT SHOP 101 VOLLYRITE 102 JUST TENNIS 103 K+T SPORTS 105 SHAPE UP 106 WOMENS SPORTS 107 ... ... 9 rows selected. CUSTOMER CUSTID ORDID ------- ------- 101 610 102 611 104 612 106 601 102 602 106 604 106 605 ... 21 rows selected. ORD ORDID ITEMID ------ ------- 610 3 611 1 612 1 601 1 602 1 ... 64 rows selected. ITEM * Additional Search Conditions Sometimes you may need to join more than two tables. For example, to display the name, the orders placed, the item numbers, the total for each item, and the total for each order for customer TKB SPORT SHOP, you will have to join the CUSTOMER, ORD, and ITEM tables. SQL> SELECT c.name, o.ordid, i.itemid, i.itemtot, o.total 2 FROM customer c, ord o, item i 3 WHERE c.custid = o.custid 4 AND o.ordid = i.ordid 5 AND c.name = 'TKB SPORT SHOP'; NAME ORDID ITEMID ITEMTOT TOTAL ------------ --------- --------- --------- --------- TKB SPORT SHOP 610 3 58 101.4 TKB SPORT SHOP 610 1 35 101.4 TKB SPORT SHOP 610 2 8.4 101.4