<?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: Lag, lead and sparse data</title>
	<atom:link href="http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/</link>
	<description>Delivered Intelligence</description>
	<lastBuildDate>Mon, 15 Mar 2010 14:12:52 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Peter Scott</title>
		<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/comment-page-1/#comment-4451</link>
		<dc:creator>Peter Scott</dc:creator>
		<pubDate>Wed, 11 Apr 2007 06:21:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/#comment-4451</guid>
		<description>Alex
Thanks for the correction - I should have been clearer in that I was referring to a &lt;i&gt;synthetic&lt;/i&gt; row generator source such as those cited by Paweł on his blog; you are quite right I would have to have a list of available date for the join - often I use  a calendar table; guess that&#039;s sticking to my Star Schema roots.</description>
		<content:encoded><![CDATA[<p>Alex<br />
Thanks for the correction &#8211; I should have been clearer in that I was referring to a <i>synthetic</i> row generator source such as those cited by Paweł on his blog; you are quite right I would have to have a list of available date for the join &#8211; often I use  a calendar table; guess that&#8217;s sticking to my Star Schema roots.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Gorbachev</title>
		<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/comment-page-1/#comment-4456</link>
		<dc:creator>Alex Gorbachev</dc:creator>
		<pubDate>Wed, 11 Apr 2007 01:56:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/#comment-4456</guid>
		<description>&lt;i&gt;but another approach (Oracle 10g) is to use a partition outer join.&lt;/i&gt;
Wouldn&#039;t you still use some kind row-generator source to join with?</description>
		<content:encoded><![CDATA[<p><i>but another approach (Oracle 10g) is to use a partition outer join.</i><br />
Wouldn&#8217;t you still use some kind row-generator source to join with?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Scott</title>
		<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/comment-page-1/#comment-4454</link>
		<dc:creator>Peter Scott</dc:creator>
		<pubDate>Tue, 10 Apr 2007 20:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/#comment-4454</guid>
		<description>Thanks Paweł
The original post was spurred by a notion that lag and lead are row based and not range based.

Filling in the gaps to &quot;put in the missing zeros&quot; is indeed probably the way most people would go for this case - row generators are one one way (as you rightly show) but another approach (Oracle 10g) is to use a partition outer join.</description>
		<content:encoded><![CDATA[<p>Thanks Paweł<br />
The original post was spurred by a notion that lag and lead are row based and not range based.</p>
<p>Filling in the gaps to &#8220;put in the missing zeros&#8221; is indeed probably the way most people would go for this case &#8211; row generators are one one way (as you rightly show) but another approach (Oracle 10g) is to use a partition outer join.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paweł Barut</title>
		<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/comment-page-1/#comment-4453</link>
		<dc:creator>Paweł Barut</dc:creator>
		<pubDate>Tue, 10 Apr 2007 20:29:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/#comment-4453</guid>
		<description>Hope this time it fill work:
&lt;code&gt;
select sal_dt, quantity, nvl(quantity,0) - nvl(SUM(quantity) over (order by sal_dt range between interval &#039;1&#039; day preceding and interval &#039;1&#039; day preceding ),0) delta
from ps_lag_1, (select (select min(sales_date) from ps_lag_1)+level-1 sal_dt
from dual connect by level &lt;= (select max(sales_date)-min(sales_date)+2 from PS_LAG_1))
where sal_dt = sales_date(+);
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hope this time it fill work:<br />
<code><br />
select sal_dt, quantity, nvl(quantity,0) - nvl(SUM(quantity) over (order by sal_dt range between interval '1' day preceding and interval '1' day preceding ),0) delta<br />
from ps_lag_1, (select (select min(sales_date) from ps_lag_1)+level-1 sal_dt<br />
from dual connect by level &lt;= (select max(sales_date)-min(sales_date)+2 from PS_LAG_1))<br />
where sal_dt = sales_date(+);<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paweł Barut</title>
		<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/comment-page-1/#comment-4452</link>
		<dc:creator>Paweł Barut</dc:creator>
		<pubDate>Tue, 10 Apr 2007 20:28:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/#comment-4452</guid>
		<description>It seems that code was broken in above comment. It should be:
select sal_dt, quantity, nvl(quantity,0) - nvl(SUM(quantity) over (order by sal_dt range between interval &#039;1&#039; day preceding and interval &#039;1&#039; day preceding ),0) delta
from ps_lag_1,
(select (select min(sales_date) from ps_lag_1)+level-1 sal_dt
from dual connect by level</description>
		<content:encoded><![CDATA[<p>It seems that code was broken in above comment. It should be:<br />
select sal_dt, quantity, nvl(quantity,0) &#8211; nvl(SUM(quantity) over (order by sal_dt range between interval &#8216;1&#8242; day preceding and interval &#8216;1&#8242; day preceding ),0) delta<br />
from ps_lag_1,<br />
(select (select min(sales_date) from ps_lag_1)+level-1 sal_dt<br />
from dual connect by level</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paweł Barut</title>
		<link>http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/comment-page-1/#comment-4455</link>
		<dc:creator>Paweł Barut</dc:creator>
		<pubDate>Tue, 10 Apr 2007 20:26:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.rittmanmead.com/2007/04/10/lag-lead-and-sparse-data/#comment-4455</guid>
		<description>Well, but still on 3rd April sales was 3 less than on second. I would rather use &lt;a href=&quot;http://pbarut.blogspot.com/2006/09/row-generators.html&quot; rel=&quot;nofollow&quot;&gt;row generator&lt;/a&gt; to fill in gaps.
&lt;code&gt;
select sal_dt, quantity, nvl(quantity,0) - nvl(SUM(quantity) over (order by sal_dt range between interval &#039;1&#039; day preceding and interval &#039;1&#039; day preceding ),0) delta
from ps_lag_1,
(select (select min(sales_date) from ps_lag_1)+level-1 sal_dt
from dual connect by level  that gives:
&lt;code&gt;
07/04/01	2	2
07/04/02	3	1
07/04/03		-3
07/04/04	5	5
07/04/05	5	0
07/04/06	3	-2
07/04/07		-3
&lt;/code&gt;
Regards,
Paweł</description>
		<content:encoded><![CDATA[<p>Well, but still on 3rd April sales was 3 less than on second. I would rather use <a href="http://pbarut.blogspot.com/2006/09/row-generators.html" rel="nofollow">row generator</a> to fill in gaps.<br />
<code><br />
select sal_dt, quantity, nvl(quantity,0) - nvl(SUM(quantity) over (order by sal_dt range between interval '1' day preceding and interval '1' day preceding ),0) delta<br />
from ps_lag_1,<br />
(select (select min(sales_date) from ps_lag_1)+level-1 sal_dt<br />
from dual connect by level  that gives:<br />
</code><code><br />
07/04/01	2	2<br />
07/04/02	3	1<br />
07/04/03		-3<br />
07/04/04	5	5<br />
07/04/05	5	0<br />
07/04/06	3	-2<br />
07/04/07		-3<br />
</code><br />
Regards,<br />
Paweł</p>
]]></content:encoded>
	</item>
</channel>
</rss>
