<?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 find the last consecutive date sequence in a SQL statement</title>
	<atom:link href="http://oraqa.com/2007/03/19/how-to-find-the-last-consecutive-date-sequence-in-a-sql-statement/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2007/03/19/how-to-find-the-last-consecutive-date-sequence-in-a-sql-statement/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Mon, 19 Dec 2011 14:21:07 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: stewstryker</title>
		<link>http://oraqa.com/2007/03/19/how-to-find-the-last-consecutive-date-sequence-in-a-sql-statement/comment-page-1/#comment-226</link>
		<dc:creator>stewstryker</dc:creator>
		<pubDate>Thu, 03 Jan 2008 21:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/03/19/how-to-find-the-last-consecutive-date-sequence-in-a-sql-statement/#comment-226</guid>
		<description>This minor (obvious) expansion of Laurent&#039;s version gives only the earliest consecutive month.
&lt;pre&gt;SELECT customer_no, min(billing_month) first_cons_month
  FROM (SELECT customer_no,
               billing_month,
               last_value(l ignore NULLS) OVER(PARTITION BY customer_no ORDER BY billing_month DESC) l,
               m
          FROM (SELECT customer_no,
                       billing_month,
                       DECODE(lag(billing_month)
                              OVER(PARTITION BY customer_no ORDER BY billing_month DESC),
                              ADD_MONTHS(billing_month, 1),
                              NULL,
                              billing_month) l,
                       MAX(billing_month) OVER(PARTITION BY customer_no) m
                  FROM cust
                 ORDER BY customer_no, billing_month DESC))
 WHERE l = m
GROUP BY customer_no;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>This minor (obvious) expansion of Laurent&#8217;s version gives only the earliest consecutive month.</p>
<pre>SELECT customer_no, min(billing_month) first_cons_month
  FROM (SELECT customer_no,
               billing_month,
               last_value(l ignore NULLS) OVER(PARTITION BY customer_no ORDER BY billing_month DESC) l,
               m
          FROM (SELECT customer_no,
                       billing_month,
                       DECODE(lag(billing_month)
                              OVER(PARTITION BY customer_no ORDER BY billing_month DESC),
                              ADD_MONTHS(billing_month, 1),
                              NULL,
                              billing_month) l,
                       MAX(billing_month) OVER(PARTITION BY customer_no) m
                  FROM cust
                 ORDER BY customer_no, billing_month DESC))
 WHERE l = m
GROUP BY customer_no;</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://oraqa.com/2007/03/19/how-to-find-the-last-consecutive-date-sequence-in-a-sql-statement/comment-page-1/#comment-204</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Wed, 21 Mar 2007 12:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/03/19/how-to-find-the-last-consecutive-date-sequence-in-a-sql-statement/#comment-204</guid>
		<description>&lt;pre&gt;
select 
  customer_no, billing_month
from (
  select customer_no, billing_month, last_value(l ignore nulls) over (partition by customer_no order by billing_month desc ) l, m
    from (
      select customer_no, 
        billing_month, 
        decode(lag(billing_month) over (partition by customer_no order by billing_month desc),
          add_months(billing_month,1),null,
          billing_month) l,
        max(billing_month) over (partition by customer_no) m
      from cust order by customer_no, billing_month desc
    )
  )
where l=m
;
&lt;/pre&gt;

may be much faster</description>
		<content:encoded><![CDATA[<pre>
select
  customer_no, billing_month
from (
  select customer_no, billing_month, last_value(l ignore nulls) over (partition by customer_no order by billing_month desc ) l, m
    from (
      select customer_no,
        billing_month,
        decode(lag(billing_month) over (partition by customer_no order by billing_month desc),
          add_months(billing_month,1),null,
          billing_month) l,
        max(billing_month) over (partition by customer_no) m
      from cust order by customer_no, billing_month desc
    )
  )
where l=m
;
</pre>
<p>may be much faster</p>
]]></content:encoded>
	</item>
</channel>
</rss>

