Create table test123 (
CustId int,
[Level] int,
RowNum int,
USAFlag bit
)
insert into test123(CustId,[Level],RowNum,USAFlag)values
(101,1,1,0),
(102,2,1,0),
(102,2,2,1),
(103,3,1,0),
(103,3,2,1),
(103,3,3,0),
(104,4,1,1),
(104,4,2,0),
(104,4,3,0),
(104,4,4,1),
(105,2,1,1),
(105,2,2,0),
(106,2,1,0),
(106,2,2,0),
(107,3,1,0),
(107,3,2,0),
(107,3,3,1),
(108,1,1,1)
CustID USARootLeaf
101 ONlyONeLevel_NonUSA
102 Leaf_USA
103 Root_Leaf_NonUSA
104 Root_Leaf_USA
105 Root_USA
106 Root_Leaf_NonUSA
107 Leaf_USA
108 OnlyOneLvel_USA
邏輯: 如果級別爲1,則基於USAFlag值USARootLeaf值應OnlyOneLvel_USA或OnlyOneLvel_NonUSA
如果級別大於1,則USARootLeaf值應爲Root_Leaf_USA,Root_Leaf_NonUSA,Root_USA,Leaf_USA,基於USAFlag的最小(級別)和最大(級別)值爲true/false
目前尚不清楚什麼時候是Leaf ......什麼時候是Root_Leaf ...... – FLICKER
如果Level> 1,您可以給出更多邏輯細節嗎? – Jason