我无法找到一种与此案例类似的案例。我援引他的知识!我每个月都会收到新颖的信件,从A到E,我需要在给每个客户的大写字母中写0。因此,如果我仅收到B,则B = 0,如果我收到A和B,则A = 1,B = 0,如果我收到A,B,C,则A = 1,B = 1,C = 0,如果我收到A和C,然后A = 1,C = 0,由客户分组。
Customer Codes
111 A
111 B
111 C
222 A
222 B
333 A
In the below SQl you're doing some row number functions and then ordering by the highest row number. After that you do another row number function by the highest row_number it gets in the cte.
With myCte
as
(
Select Customer,Code,Row_Number() OVER (PARTITION BY Customer Order By Code) rn
from myTable
)
select Customer,Code,
Case when rn2 = 1 then 0
else 1
end as myArbitraryNumber
from
(
select Customer, Code, rn, Row_Number() OVER (Partition by Customer,rn Order by rn DESC) rn2
from myCte
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句