1
我有2代表這是賬戶TBL和客戶TBL,結構如下圖所示:ORACLE SQL查詢與親子結構
帳戶TBL
Customer_ID Account_ID Parent_Account_ID
3780952 3780952 3780952
3780997 3780997 3780997
3781004 3781004 3780997
客戶TBL(Customer_Group有不同的價值,但我只對個人有興趣)
Customer_ID Customer_Group
3781004 Personal
3780997 Personal
3780952 Personal
規則d etermine PS/NonPS,原則,增刊按如下:
**PS/NonPs**
Customer_ID equal to Parent_Account and Parent_Account is unique (not exist more than 1) then NonPs.
Customer_ID equal to Parent_Account and Parent_Account is non unique OR - Customer_ID is not equal to Parent_Account then PS
**Principle**
IF NonPS then Principle is Null
IF PS - If Customer_ID equal to Parent_Account then Principle is Y else N
**Supp**
IF NonPS then Supp is Null
IF PS - If Customer_ID not equal to Parent_Account then supp is Y else N
最終的輸出應該是這樣的
Customer_ID Account_ID Parent_Account_ID PS/NonPS Principle Supp
3780952 3780952 3780952 NonPS Null Null
3780997 3780997 3780997 PS Y N
3781004 3781004 3780997 PS N Y
我alredy試過很多次,但不能仍然獲得output..anyone能幫忙嗎?
+1我在做,而你正在做的:P – 2012-01-17 11:20:20
有助於me..thanks很多 – user871695 2012-01-18 02:23:19