我有一张这样的表
请原谅他们由内部标准驱动的列名。我想知道的是如何查询这个自引用表,所以输出是这样的:
| PARENT REASON | CHILD REASON |
| ---------------------------------|
| Electrical | Wire Broke |
| Electrical | Fuse Blown |
| Mechanical | Bad Gear |
| Mechanical | Bolt Broke |
非常感谢您的帮助。
答案 0 :(得分: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
答案 1 :(得分: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