怎麼組裝一台車?

SQL Server 的階層式與遞迴查詢

Jasmin Ludolf

Content Developer

拆解一台車

一張關於拆解汽車的圖片。

SQL Server 的階層式與遞迴查詢

汽車零件清單

零組件層級:

  • Level 1SUVCabrio
  • Level 2BodyEngineInterior DecorationWheel
  • Level 3DoorHoodEngine BodyCylinderSeats

汽車零件的階層

SQL Server 的階層式與遞迴查詢

建立資料模型

建立階層的要素:

  • PartIDSubPartID

描述特性的要素:

  • ComponentEngine
  • TitleV6BiTurbo
  • VendorBMW
  • ProductKeyEV3891ASF
  • Cost3000
  • Quantity1

BillOfMaterial 的資料模型說明

SQL Server 的階層式與遞迴查詢

使用階層式資料模型

  • 組成汽車的零件各有哪些層級?
+-----------------+---------------------------+
| Component       | Level                     |
|-----------------|---------------------------|
| SUV             | 1                         |
|-----------------|---------------------------|
| Body            | 2                         |
|-----------------|---------------------------|
| Hood            | 3                         |
+-----------------+---------------------------+
SQL Server 的階層式與遞迴查詢

使用階層式資料模型

  • 在每個零件層級中,組裝一台車各零件總數是多少?
+-----------------+---------------------------+
| Component       | Quantity                  |
|-----------------|---------------------------|
| SUV             | 1                         |
|-----------------|---------------------------|
| Body            | 1                         |
|-----------------|---------------------------|
| Wheels          | 4                         |
+-----------------+---------------------------+
SQL Server 的階層式與遞迴查詢

一起來組一台車!

SQL Server 的階層式與遞迴查詢

Preparing Video For Download...