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

DECLARE @Table TABLE( Tasa DECIMAL(18,2), ACUM1 DECIMAL(18,2), ACUM2 DECIMAL(18,2) ) INSERT INTO @Table VALUES(0.3,758763300.00,758763300.00) INSERT INTO @Table VALUES(0.35,821263300.00,821263300) INSERT INTO @Table VALUES(0.36,1021263300.00,0.00) INSERT INTO @Table VALUES(0.36,1021263300.00,0.00) INSERT INTO @Table VALUES(0.36,1021263300.00,0.00) INSERT INTO @Table VALUES(0.36,1021263300.00,0.00) INSERT INTO @Table VALUES(0.36,1021263300.00,0.00) INSERT INTO @Table VALUES(0.36,1021263300.00,0.00) ;WITH CTE_ AS ( --AQUI VA TU SELECT NORMAL SIN LA VARIABLE SEL --YO HAGO UN SELECT FROM PARA SIMULAR EL RESULTADO DEL CTE SELECT * FROM @Table ), CTE_SEL AS ( SELECT ROW_NUMBER() OVER (PARTITION BY ACUM2 ORDER BY ACUM2 DESC) AS RN,* FROM CTE_ ) SELECT CASE WHEN RN=1 AND ACUM2=0 THEN 'X' ELSE '' END SEL,Tasa,ACUM1,ACUM2 FROM CTE_SEL ORDER BY ACUM2 DESC
SEL Tasa ACUM1 ACUM2
0.35 821263300.00 821263300.00
0.30 758763300.00 758763300.00
X 0.36 1021263300.00 0.00
0.36 1021263300.00 0.00
0.36 1021263300.00 0.00
0.36 1021263300.00 0.00
0.36 1021263300.00 0.00
0.36 1021263300.00 0.00
 hidden batch(es)