title: Sql server ROW_NUMBER() & Rank() function detail....how it works
body: <p>i never use sql server ROW_NUMBER() function. so i read some article regarding ROW_NUMBER(),PARTITION &amp; RANK() etc but still not clear to me.</p>
  
  <p>i found the syntax is like</p>
  
  <pre><code>SELECT top 10 ROW_NUMBER() OVER(ORDER BY JID DESC) AS 'Row Number',
  JID,Specialist,  jobstate, jobtype FROM bbajobs
  
  SELECT top 10 ROW_NUMBER() OVER(PARTITION  BY JID ORDER BY JID DESC) AS 'Row Number',
  JID,Specialist,  jobstate, jobtype FROM bbajobs
  </code></pre>
  
  <p>i have few question</p>
  
  <pre><code>1) what over() function does. why we need to specify column name in over function like OVER(ORDER BY JID DESC)
  
  2) i saw sometime people use PARTITION  keyword. what it is?
  it is also used in over function like OVER(PARTITION  BY JID ORDER BY JID DESC)
  3) in what type of situation we have to use PARTITION  keyword
  4) when we specify PARTITION  keyword in over then also we need to specify order by    also why. only PARTITION  keyword can not be used in over clause.
  5) what type of situation one should use RANK function
  6) what is CTE and what is the advantage of using CTE. it is just like temporary view.
  anyone get any performance boost if he/she use CTE other than reusability?
  </code></pre>
  
  <p>please discuss my points in detail. it will be very much helpful if some one make me understand with small &amp; easy example for all the keyword like ROW_NUMBER(),PARTITION &amp; RANK(). thanks</p>