<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL: Ranking without self join</title>
	<atom:link href="http://code.openark.org/blog/mysql/sql-ranking-without-self-join/feed" rel="self" type="application/rss+xml" />
	<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join</link>
	<description>Blog by Shlomi Noach</description>
	<lastBuildDate>Wed, 01 Feb 2012 20:47:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-54745</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Thu, 13 Oct 2011 18:07:36 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-54745</guid>
		<description>@Nandhagopal,
You would use something like this:
@step := IF(@prev = @curr, @step+1, 1) AS step
@rank := IF(@prev = @curr, @rank, @rank+@step) AS rank
...
SELECT @step := 1</description>
		<content:encoded><![CDATA[<p>@Nandhagopal,<br />
You would use something like this:<br />
@step := IF(@prev = @curr, @step+1, 1) AS step<br />
@rank := IF(@prev = @curr, @rank, @rank+@step) AS rank<br />
...<br />
SELECT @step := 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nandhagopal</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-54737</link>
		<dc:creator>Nandhagopal</dc:creator>
		<pubDate>Thu, 13 Oct 2011 16:42:51 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-54737</guid>
		<description>I am new to the world of sql, so I apologise if my doubt sounds childish... In your examples, if two people are tied for the second spot then the one following them is 3rd. In actual conventional ranking systems, we place that fellow 4th. So, how would you change your query to incorporate it such that if m people are tied for the n&#039;th rank, then the next person after them must be ranked (m+n).</description>
		<content:encoded><![CDATA[<p>I am new to the world of sql, so I apologise if my doubt sounds childish... In your examples, if two people are tied for the second spot then the one following them is 3rd. In actual conventional ranking systems, we place that fellow 4th. So, how would you change your query to incorporate it such that if m people are tied for the n'th rank, then the next person after them must be ranked (m+n).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Subrata</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-36708</link>
		<dc:creator>Subrata</dc:creator>
		<pubDate>Tue, 12 Apr 2011 09:13:04 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-36708</guid>
		<description>Try this one

SELECT
  s1.score_id, s1.student_name, s1.score, COUNT(DISTINCT s2.score) AS rank
FROM
  score s1 JOIN score s2 ON (s1.score &lt;= s2.score)
GROUP BY s1.score_id ORDER BY rank</description>
		<content:encoded><![CDATA[<p>Try this one</p>
<p>SELECT<br />
  s1.score_id, s1.student_name, s1.score, COUNT(DISTINCT s2.score) AS rank<br />
FROM<br />
  score s1 JOIN score s2 ON (s1.score &lt;= s2.score)<br />
GROUP BY s1.score_id ORDER BY rank</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bigcode</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-22929</link>
		<dc:creator>bigcode</dc:creator>
		<pubDate>Sat, 11 Dec 2010 15:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-22929</guid>
		<description>I don&#039;t have an example of doing a rank without the self join but my example does allow for grouping.
http://bigcode.wordpress.com/2010/12/11/5/</description>
		<content:encoded><![CDATA[<p>I don't have an example of doing a rank without the self join but my example does allow for grouping.<br />
<a href="http://bigcode.wordpress.com/2010/12/11/5/" rel="nofollow">http://bigcode.wordpress.com/2010/12/11/5/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-18828</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Tue, 12 Oct 2010 05:32:46 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-18828</guid>
		<description>@Mark,

Was taught that a couple of years ago here:
&lt;a href=&quot;http://code.openark.org/blog/mysql/dynamic-sequencing-with-a-single-query#comment-63&quot; rel=&quot;nofollow&quot;&gt;http://code.openark.org/blog/mysql/dynamic-sequencing-with-a-single-query#comment-63&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>@Mark,</p>
<p>Was taught that a couple of years ago here:<br />
<a href="http://code.openark.org/blog/mysql/dynamic-sequencing-with-a-single-query#comment-63" rel="nofollow">http://code.openark.org/blog/mysql/dynamic-sequencing-with-a-single-query#comment-63</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Plutowski</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-18773</link>
		<dc:creator>Mark Plutowski</dc:creator>
		<pubDate>Mon, 11 Oct 2010 20:44:47 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-18773</guid>
		<description>@shlomi: thanks for the neat trick of using cross join to initialize the variables. 

@GSnyder : this matters when using a tool (e.g., BI or reporting tool) that only allows entering a single SQL statement. 

@Jay: as you say: &quot;Now try your trick when you need a GROUP BY&quot;  -- Indeedy, unfort&#039;y this is the showstopper for me too.  I can&#039;t get it to work with a GROUP BY.  

But hey, I still got one neat trick out of this, so thanks again for that Shlomi !</description>
		<content:encoded><![CDATA[<p>@shlomi: thanks for the neat trick of using cross join to initialize the variables. </p>
<p>@GSnyder : this matters when using a tool (e.g., BI or reporting tool) that only allows entering a single SQL statement. </p>
<p>@Jay: as you say: "Now try your trick when you need a GROUP BY"  -- Indeedy, unfort'y this is the showstopper for me too.  I can't get it to work with a GROUP BY.  </p>
<p>But hey, I still got one neat trick out of this, so thanks again for that Shlomi !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2010-06-25 &#124; Digitalistic - Mashup or die trying</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-15133</link>
		<dc:creator>links for 2010-06-25 &#124; Digitalistic - Mashup or die trying</dc:creator>
		<pubDate>Fri, 25 Jun 2010 14:03:51 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-15133</guid>
		<description>[...] SQL: Ranking without self join &#124; code.openark.org (tags: sql join ranking optimization mysql) [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL: Ranking without self join | code.openark.org (tags: sql join ranking optimization mysql) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-10147</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Tue, 02 Feb 2010 19:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-10147</guid>
		<description>George,

Reset as in @c := 0, nothing fancy...</description>
		<content:encoded><![CDATA[<p>George,</p>
<p>Reset as in @c := 0, nothing fancy...</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-10146</link>
		<dc:creator>George</dc:creator>
		<pubDate>Tue, 02 Feb 2010 19:38:16 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-10146</guid>
		<description>Hi Shlomi,

This piece of gold has already helped me immensely, thanks.

As per #18, how would I reset the other variable? I cannot seem to find anything on mysql.com</description>
		<content:encoded><![CDATA[<p>Hi Shlomi,</p>
<p>This piece of gold has already helped me immensely, thanks.</p>
<p>As per #18, how would I reset the other variable? I cannot seem to find anything on mysql.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MySQL: Another Ranking trick &#171; JZ Talk Blogger</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-9602</link>
		<dc:creator>MySQL: Another Ranking trick &#171; JZ Talk Blogger</dc:creator>
		<pubDate>Thu, 21 Jan 2010 07:28:32 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-9602</guid>
		<description>[...] Another Ranking trick I just read SQL: Ranking without self join, in which Shlomi Noach shares a nice MySQL-specific trick based on user-defined variables to [...]</description>
		<content:encoded><![CDATA[<p>[...] Another Ranking trick I just read SQL: Ranking without self join, in which Shlomi Noach shares a nice MySQL-specific trick based on user-defined variables to [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

