title: Take the first line of the every partition
body: <p>I have this query : </p>
  
  <pre><code>select   ROW_NUMBER() OVER ( PARTITION BY codtiers ORDER BY case when isnull(cumulapport, 0) &gt; isnull(cumulretrait, 0) then cumulapport
   else cumulretrait
  end DESC ) AS classement,
                      codTiers
             from     dbo.TiersComptesLocal 
             group by codTiers
  </code></pre>
  
  <p>which return this result :</p>
  
  <pre><code>classement  |  codTiers  
  -------------------------
      1       |  1XXXXX
      2       |  1XXXXX
      1       |  1YYXXX
      2       |  1YYXXX
      3       |  1YYXXX
      1       |  1XXXYY
  </code></pre>
  
  <p>I want to display the first line from every partition
  I want to have a result like this : </p>
  
  <pre><code>classement  |  codTiers  
  -------------------------
      1       |  1XXXXX
      1       |  1YYXXX
      1       |  1XXXYY
  </code></pre>
  
  <p>Any idea will be appreciate.</p>
  
  <p>this is my full query :</p>
  
  <pre><code>select   ROW_NUMBER() OVER ( PARTITION BY tcl_codtiers ORDER BY case when isnull(cumulapport, 0) &gt; isnull(cumulretrait, 0) then cumulapport
                                                                                                                  else cumulretrait
                                                                                                             end DESC ) AS classement,
  
                                          TCL_CodTiers,
                                          'le montant max des ' + Senscumul + ' ( '
                          + convert(varchar(50), '') + ' € ) du tiers titulaire '
                          + TCL_CodTiers + ' ( ' + ''
                          + ' ) est supérieur au seuil fixé dans l''alerte : '
                          + '75000'
  
                                 from     dbo.CLI_TCL_TiersComptesLocal
                                          INNER JOIN dbo.CLI_GCO_GeneriquesComptes ON TCL_CodTiers = GCO_CodTiersPrincipal
                                                                                      AND TCL_NumLien IN ( 0, 1 )
                                                                      inner join ( select TCL_CodTiers CodTiers,
                                                                  sum(case when ESO_MntValoRetenuEnEuros &gt; 0
                                                                           then ESO_MntValoRetenuEnEuros
                                                                           else 0
                                                                      end) cumulapport,
                                                                  sum(case when ESO_MntValoRetenuEnEuros &lt; 0
                                                                           then abs(ESO_MntValoRetenuEnEuros)
                                                                           else 0
                                                                      end) cumulretrait, 
                                                                        case when isnull(  sum(case when ESO_MntValoRetenuEnEuros &gt; 0
                                                                           then ESO_MntValoRetenuEnEuros
                                                                           else 0
                                                                      end), 0) &gt; isnull( sum(case when ESO_MntValoRetenuEnEuros &lt; 0
                                                                           then abs(ESO_MntValoRetenuEnEuros)
                                                                           else 0
                                                                      end), 0)
                                                   then 'Apports'
                                                   else 'Retraits'
                                              end as Senscumul
                                                           from   CRO_ESO_EntreeSortie
                                                                  inner join CLI_TCL_TiersComptesLocal on TCL_CodCompte = ESO_CodCompte
                                                                                                          and TCL_NumLien in ( 0, 1 )
                                                           group by TCL_CodTiers
                                                           having sum(case when ESO_MntValoRetenuEnEuros &gt; 0
                                                                           then ESO_MntValoRetenuEnEuros
                                                                           else 0
                                                                      end) &gt; 75000
                                                                  or sum(case when ESO_MntValoRetenuEnEuros &lt; 0
                                                                              then abs(ESO_MntValoRetenuEnEuros)
                                                                              else 0
                                                                         end) &gt; 75000
                                                         ) surveillance on GCO_CodTiersPrincipal = CodTiers
  </code></pre>
  
  <p>Thanks in advance.</p>