select t13.CKind,t13.CValue
from @t t1 ,@t t2 ,@t t3 ,@t t4 ,@t t5 ,@t t6 ,@t t7 ,@t t8 ,@t t9 ,@t t10 ,@t t11 ,@t t12 ,@t t13 
where 
t2.CQue not in (t1.CQue) and t2.CKind=t1.CKind   --不可以重复,而且必须是同一类型
and t3.CQue not in (t1.CQue,t2.CQue) and t3.CKind=t2.CKind  and t3.CKind=t1.CKind  --
and (t3.CValue >= t2.CValue and  t2.CValue>= t1.CValue and t3.CValue >= t1.CValue ) -- 排序
and ((t3.CValue=t2.CValue and t2.CValue =t1.CValue  and  t3.CValue =t1.CValue) 
or ( t1.CKind<>4 and t2.CKind<>4 and t3.CKind <> 4 
and t3.CValue=t2.CValue+1 and t3.CValue=t1.CValue+2 and t2.CValue=t1.CValue+1


and t4.CQue not in (t1.CQue,t2.CQue,t3.CQue)
and t5.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue) and t5.CKind=t4.CKind 
and t6.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue) and t6.CKind=t5.CKind and t6.CKind=t4.CKind 
and (t6.CValue >= t5.CValue and  t5.CValue>= t4.CValue and t6.CValue >= t4.CValue ) -- 排序
and ((t6.CValue=t5.CValue and t5.CValue =t4.CValue  and  t6.CValue =t4.CValue) or ( t4.CKind<>4 and t5.CKind<>4 and t6.CKind <> 4 and  t6.CValue=t5.CValue+1 and t6.CValue=t4.CValue+2 and t5.CValue=t4.CValue+1)) 

--and t4.CKind >= t1.Ckind --and t4.CValue >= t1.CValue
and t7.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue)
and t8.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue) and t8.CKind=t7.CKind 
and t9.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue) and t9.CKind=t8.CKind and t9.CKind=t7.CKind 
and (t9.CValue >= t8.CValue and  t8.CValue>= t7.CValue and t9.CValue >= t7.CValue ) -- 排序
and ((t9.CValue=t8.CValue and t8.CValue =t7.CValue  and  t9.CValue =t7.CValue) or ( t7.CKind<>4 and t8.CKind<>4 and t9.CKind <> 4 and  t9.CValue=t8.CValue+1 and t9.CValue=t7.CValue+2 and t8.CValue=t7.CValue+1)) 
--and  t7.CKind >= t4.Ckind --and t7.CValue >= t4.CValue

and t10.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue)
and t11.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue,t10.CQue) and t11.CKind=t10.CKind 
and t12.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue,t10.CQue,t11.CQue) and t12.CKind=t11.CKind  and t12.CKind=t10.CKind 
and (t12.CValue >= t11.CValue and  t11.CValue>= t10.CValue and t12.CValue >= t10.CValue ) -- 排序
and ((t12.CValue=t11.CValue and t11.CValue =t10.CValue  and  t12.CValue =t10.CValue) or ( t10.CKind<>4 and t11.CKind<>4 and t12.CKind <> 4 and   t12.CValue=t11.CValue+1 and t12.CValue=t10.CValue+2 and t12.CValue=t11.CValue+1)) 

--and  t10.CKind >= t7.Ckind --and t4.CValue >= t1.CValue
and t13.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue,t10.CQue,t11.CQue,T12.CQue)

union all 
select t13.Ckind,case when t13.CKind = 4 then t13.CValue else t13.CValue+(t12.CValue-t13.CValue) end CValue
--,*
from @t t1 ,@t t2 ,@t t3 ,@t t4 ,@t t5 ,@t t6 ,@t t7 ,@t t8 ,@t t9 ,@t t10 ,@t t11 ,@t t12 ,@t t13 
where 
t2.CQue not in (t1.CQue) and t2.CKind=t1.CKind   --不可以重复,而且必须是同一类型
and t3.CQue not in (t1.CQue,t2.CQue) and t3.CKind=t2.CKind  and t3.CKind=t1.CKind  --
and (t3.CValue >= t2.CValue and  t2.CValue>= t1.CValue and t3.CValue >= t1.CValue ) -- 排序
and ((t3.CValue=t2.CValue and t2.CValue =t1.CValue  and  t3.CValue =t1.CValue) 
or ( t1.CKind<>4 and t2.CKind<>4 and t3.CKind <> 4 
and t3.CValue=t2.CValue+1 and t3.CValue=t1.CValue+2 and t2.CValue=t1.CValue+1


and t4.CQue not in (t1.CQue,t2.CQue,t3.CQue)
and t5.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue) and t5.CKind=t4.CKind 
and t6.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue) and t6.CKind=t5.CKind and t6.CKind=t4.CKind 
and (t6.CValue >= t5.CValue and  t5.CValue>= t4.CValue and t6.CValue >= t4.CValue ) -- 排序
and ((t6.CValue=t5.CValue and t5.CValue =t4.CValue  and  t6.CValue =t4.CValue) or ( t4.CKind<>4 and t5.CKind<>4 and t6.CKind <> 4 and  t6.CValue=t5.CValue+1 and t6.CValue=t4.CValue+2 and t5.CValue=t4.CValue+1)) 

--and t4.CKind >= t1.Ckind --and t4.CValue >= t1.CValue
and t7.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue)
and t8.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue) and t8.CKind=t7.CKind 
and t9.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue) and t9.CKind=t8.CKind and t9.CKind=t7.CKind 
and (t9.CValue >= t8.CValue and  t8.CValue>= t7.CValue and t9.CValue >= t7.CValue ) -- 排序
and ((t9.CValue=t8.CValue and t8.CValue =t7.CValue  and  t9.CValue =t7.CValue) or ( t7.CKind<>4 and t8.CKind<>4 and t9.CKind <> 4 and  t9.CValue=t8.CValue+1 and t9.CValue=t7.CValue+2 and t8.CValue=t7.CValue+1)) 
--and  t7.CKind >= t4.Ckind --and t7.CValue >= t4.CValue

and t10.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue) 
and t11.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue,t10.CQue) and t11.CKind=t10.CKind  and t11.CKind=t10.CKind and t11.CValue=t10.CValue and t10.CQue<t11.CQue
and t12.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue,t10.CQue,t11.CQue) 
and t13.CQue not in (t1.CQue,t2.CQue,t3.CQue,t4.CQue,t5.CQue,t6.CQue,t7.CQue,t8.CQue,t9.CQue,t10.CQue,t11.CQue,T12.CQue)
and t13.Ckind=T12.CKind and abs(T13.CValue)-(t12.CValue) <= 1 
and ( (t13.CKind = 4 and t13.CValue=t12.CValue) or (t13.Ckind<> 4 and (t13.CValue+(t12.CValue-t13.CValue)) between 1 and 9) )