<?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: How to simulate the SQL ROW_NUMBER function</title>
	<atom:link href="http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/</link>
	<description>Stay curious!</description>
	<lastBuildDate>Thu, 09 Feb 2012 09:56:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: SMAH1</title>
		<link>http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/#comment-19170</link>
		<dc:creator>SMAH1</dc:creator>
		<pubDate>Mon, 21 Feb 2011 18:24:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=10#comment-19170</guid>
		<description>Hi

Thank you for useful articles.
But there is problem!

in below sample (in SQL SERVER):

CREATE TABLE [Test] (
	[ID] [bigint] IDENTITY (1, 1) NOT NULL ,
	[Date] [char] (10),
	[B] [int],
	[C] [int]
)
INSERT INTO [TEST].[Test]
     VALUES (&#039;1389/01/01&#039;,&#039;1&#039;,&#039;1&#039;)
INSERT INTO [TEST].[Test]
     VALUES (&#039;1389/01/01&#039;,&#039;5&#039;,&#039;2&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/02&#039;,&#039;2&#039;,&#039;10&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/02&#039;,&#039;2&#039;,&#039;11&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/03&#039;,&#039;2&#039;,&#039;2&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/03&#039;,&#039;5&#039;,&#039;1&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/01&#039;,&#039;2&#039;,&#039;1&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/02&#039;,&#039;2&#039;,&#039;12&#039;)
INSERT INT[TEST].[Test]
     VALUES (&#039;1389/01/03&#039;,&#039;2&#039;,&#039;2&#039;)

when we use:

select l.Date, l.B, l.C, count(*) as num
from Test as l
left outer join Test as r
    on l.Date = r.Date
    and l.B &gt;= r.B
group by l.Date, l.B, l.C

we have:

...
1389/01/02	2	10	3
1389/01/02	2	11	3
1389/01/02	2	12	3
...

But must be create like : 

...
1389/01/02	2	10	1
1389/01/02	2	11	2
1389/01/02	2	12	3
...

No my question:
What solve it? (Create above table)?
Note : I want use SQL only (No use TSQL)!
Note 2 : Cause problem is &#039;Like Data in Date and B Field&#039;

Description 1: My english is poor.Excuse me!
Description 2: Date is persian calender!</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Thank you for useful articles.<br />
But there is problem!</p>
<p>in below sample (in SQL SERVER):</p>
<p>CREATE TABLE [Test] (<br />
	[ID] [bigint] IDENTITY (1, 1) NOT NULL ,<br />
	[Date] [char] (10),<br />
	[B] [int],<br />
	[C] [int]<br />
)<br />
INSERT INTO [TEST].[Test]<br />
     VALUES (&#8217;1389/01/01&#8242;,&#8217;1&#8242;,&#8217;1&#8242;)<br />
INSERT INTO [TEST].[Test]<br />
     VALUES (&#8217;1389/01/01&#8242;,&#8217;5&#8242;,&#8217;2&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/02&#8242;,&#8217;2&#8242;,&#8217;10&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/02&#8242;,&#8217;2&#8242;,&#8217;11&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/03&#8242;,&#8217;2&#8242;,&#8217;2&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/03&#8242;,&#8217;5&#8242;,&#8217;1&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/01&#8242;,&#8217;2&#8242;,&#8217;1&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/02&#8242;,&#8217;2&#8242;,&#8217;12&#8242;)<br />
INSERT INT[TEST].[Test]<br />
     VALUES (&#8217;1389/01/03&#8242;,&#8217;2&#8242;,&#8217;2&#8242;)</p>
<p>when we use:</p>
<p>select l.Date, l.B, l.C, count(*) as num<br />
from Test as l<br />
left outer join Test as r<br />
    on l.Date = r.Date<br />
    and l.B &gt;= r.B<br />
group by l.Date, l.B, l.C</p>
<p>we have:</p>
<p>&#8230;<br />
1389/01/02	2	10	3<br />
1389/01/02	2	11	3<br />
1389/01/02	2	12	3<br />
&#8230;</p>
<p>But must be create like : </p>
<p>&#8230;<br />
1389/01/02	2	10	1<br />
1389/01/02	2	11	2<br />
1389/01/02	2	12	3<br />
&#8230;</p>
<p>No my question:<br />
What solve it? (Create above table)?<br />
Note : I want use SQL only (No use TSQL)!<br />
Note 2 : Cause problem is &#8216;Like Data in Date and B Field&#8217;</p>
<p>Description 1: My english is poor.Excuse me!<br />
Description 2: Date is persian calender!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian M</title>
		<link>http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/#comment-18652</link>
		<dc:creator>Brian M</dc:creator>
		<pubDate>Tue, 14 Sep 2010 15:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=10#comment-18652</guid>
		<description>If you want a simple way to reproduce the row_number without grouping its easily achieved with a user variable.

SELECT	*, @rownum:=@rownum+1 rownum, (SELECT @rownum:=0) dummy
FROM	fruits
HAVING rownum &lt;= (pg*lim);

You&#039;ll notice I used it for dynamic paging of the result set in my stored proc.</description>
		<content:encoded><![CDATA[<p>If you want a simple way to reproduce the row_number without grouping its easily achieved with a user variable.</p>
<p>SELECT	*, @rownum:=@rownum+1 rownum, (SELECT @rownum:=0) dummy<br />
FROM	fruits<br />
HAVING rownum &lt;= (pg*lim);</p>
<p>You&#039;ll notice I used it for dynamic paging of the result set in my stored proc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeilen in MySQL enumerieren Lars seine Seite</title>
		<link>http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/#comment-18034</link>
		<dc:creator>Zeilen in MySQL enumerieren Lars seine Seite</dc:creator>
		<pubDate>Mon, 15 Mar 2010 23:14:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=10#comment-18034</guid>
		<description>[...] Eine weitere Möglichkeit beschreibt Xarpb in seinem Artikel How to simulate the SQL ROW_NUMBER function. [...]</description>
		<content:encoded><![CDATA[<p>[...] Eine weitere Möglichkeit beschreibt Xarpb in seinem Artikel How to simulate the SQL ROW_NUMBER function. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shiva M</title>
		<link>http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/#comment-17818</link>
		<dc:creator>Shiva M</dc:creator>
		<pubDate>Mon, 15 Feb 2010 23:28:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=10#comment-17818</guid>
		<description>In my above comment &quot;not equal to&quot; with greater than and less than got gobbled up. Hence replaced it with &quot;!=&quot;.

SET @n := 0;
SET @t := NULL;
SELECT f.*, @n
  FROM fruits f
  WHERE CASE WHEN f.type != @t THEN @n := 0 ELSE 1 END &gt;= 0
       AND(@n := @n + 1) &gt;= 0
       AND(@t := f.type) IS NOT NULL</description>
		<content:encoded><![CDATA[<p>In my above comment &#8220;not equal to&#8221; with greater than and less than got gobbled up. Hence replaced it with &#8220;!=&#8221;.</p>
<p>SET @n := 0;<br />
SET @t := NULL;<br />
SELECT f.*, @n<br />
  FROM fruits f<br />
  WHERE CASE WHEN f.type != @t THEN @n := 0 ELSE 1 END &gt;= 0<br />
       AND(@n := @n + 1) &gt;= 0<br />
       AND(@t := f.type) IS NOT NULL</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shiva M</title>
		<link>http://www.xaprb.com/blog/2005/09/27/simulating-the-sql-row_number-function/#comment-17817</link>
		<dc:creator>Shiva M</dc:creator>
		<pubDate>Mon, 15 Feb 2010 23:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=10#comment-17817</guid>
		<description>One more solution,

SET @n := 0;
SET @t := NULL;
SELECT f.*, @n
  FROM fruits f
  WHERE CASE WHEN f.type  @t THEN @n := 0 ELSE 1 END &gt;= 0
       AND(@n := @n + 1) &gt;= 0
       AND(@t := f.type) IS NOT NULL</description>
		<content:encoded><![CDATA[<p>One more solution,</p>
<p>SET @n := 0;<br />
SET @t := NULL;<br />
SELECT f.*, @n<br />
  FROM fruits f<br />
  WHERE CASE WHEN f.type  @t THEN @n := 0 ELSE 1 END &gt;= 0<br />
       AND(@n := @n + 1) &gt;= 0<br />
       AND(@t := f.type) IS NOT NULL</p>
]]></content:encoded>
	</item>
</channel>
</rss>

