登录 注册
当前位置:主页 > 资源下载 > SQL语言基础:连接多个表

SQL语言基础:连接多个表

  • 更新:2024-07-07 11:33:44
  • 大小:5.26MB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:Informix - 数据库
  • 格式:PPT

资源介绍

连接多个表 * 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