0

我有一张这样的桌子

在此处输入图像描述

请原谅它们由内部标准驱动的列名。我想知道的是如何查询这个自引用表,所以输出是这样的:

| PARENT REASON |    CHILD REASON  |
| ---------------------------------|
| Electrical    | Wire Broke       |
| Electrical    | Fuse Blown       |
| Mechanical    | Bad Gear         |
| Mechanical    | Bolt Broke       |

非常感谢您的帮助。

4

2 回答 2

1
SELECT T2.strReason as [PARENT REASON], T1.strReason as [CHILD REASON]
FROM IngTable as T1
JOIN IngTable as T2
  ON T1.IngReasonParent = T2.IngReason
于 2013-09-17T18:26:19.080 回答
0

我相信你应该把它分成一个类别表,但是......

SELECT SELECT a.strReason as [PARENT REASON], b.strReason as [CHILD REASON]
FROM table1 AS a 
INNER JOIN table1 as b ON b.lngReasonParent = a.lngReason 
于 2013-09-17T18:27:51.777 回答