clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3364508 fiddles created (36321 in the last week).

CREATE FUNCTION f(@ NVARCHAR(MAX))RETURNS TABLE RETURN SELECT q/21+IIF(d>6,2,IIF(d=6,1,0))+IIF(m=0,IIF(n=0 AND a>b,1,0),IIF(n=0 OR a>b,1,0))p FROM(SELECT SUM(q)q,MAX(IIF(s='D',q,0))d,SUM(a)a,MIN(q)m,SUM(b)b,MIN(10-q)n FROM(SELECT s,COUNT(k)q,MAX(IIF(r=k,v,0))a,MAX(IIF(r=k,0,v))b FROM(SELECT LEFT(value,1)r,s,ASCII(RIGHT(value,1))-38 v FROM STRING_SPLIT('7;,68,A6,5,4,3,2,Q0,J0,K0',','),(VALUES('D'),('C'),('H'),('S'))s(s))d LEFT JOIN(SELECT LEFT(value,1)k,RIGHT(value,1)u FROM STRING_SPLIT(@,','))a ON r+s=k+u GROUP BY s)t)t
 hidden batch(es)


SELECT * FROM (VALUES ('7D,6D,AD,5D,4D,3D,2D,QD,7C,6C,4C,3C,2C,7H,4H,2H,5S,3S,QS,JS,KS'), ('3D,7C,6C,AC,5C,4C,3C,2C,QC,4H,7S'), ('7D,6D,AD,5D,4D,3D,2D,7C,6C,AC,5C,4C,3C,2C,7H,6H,AH,5H,4H,3H,2H'), ('7D,6D,AD,5D,4D,3D,2D,QD,JD,KD,QC,QH,QS'), ('7D,6D,AD,5D,4D,3D,2D,QD,JD,KD,7C,7H'), ('7D,6D,AD,5D,4D,3D,2D,QD,JD,KD,QC,QH'), ('')) AS Rounds(cards) CROSS APPLY f(cards) AS f;
cards p
7D,6D,AD,5D,4D,3D,2D,QD,7C,6C,4C,3C,2C,7H,4H,2H,5S,3S,QS,JS,KS 4
3D,7C,6C,AC,5C,4C,3C,2C,QC,4H,7S 0
7D,6D,AD,5D,4D,3D,2D,7C,6C,AC,5C,4C,3C,2C,7H,6H,AH,5H,4H,3H,2H 3
7D,6D,AD,5D,4D,3D,2D,QD,JD,KD,QC,QH,QS 3
7D,6D,AD,5D,4D,3D,2D,QD,JD,KD,7C,7H 3
7D,6D,AD,5D,4D,3D,2D,QD,JD,KD,QC,QH 2
0
Warning: Null value is eliminated by an aggregate or other SET operation.
 hidden batch(es)