-
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
- 上一篇: 限定不明确的列名-SQL语言基础
- 下一篇: 用非等连接查询记录-SQL语言基础