怎麼組裝一台車?

SQL Server 的階層式與遞迴查詢

Jasmin Ludolf

Content Developer

拆解一台車

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

SQL Server 的階層式與遞迴查詢

汽車零件清單

零組件層級:

  • Level 1:SUV、Cabrio
  • Level 2:Body、Engine、Interior Decoration、Wheel
  • Level 3:Door、Hood、Engine Body、Cylinder、Seats

汽車零件的階層

SQL Server 的階層式與遞迴查詢

建立資料模型

建立階層的要素:

  • PartID 與 SubPartID

描述特性的要素:

  • Component:Engine
  • Title:V6BiTurbo
  • Vendor:BMW
  • ProductKey:EV3891ASF
  • Cost:3000
  • Quantity:1

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...