<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL Challenges</title>
	<atom:link href="http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/</link>
	<description>Miscellaneous Random Oracle Topics: Stop, Think, ... Understand</description>
	<lastBuildDate>Mon, 13 May 2013 14:10:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-5250</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 11 Feb 2013 01:11:05 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-5250</guid>
		<description><![CDATA[Morgan,

Thank you for offering a solution to this SQL challenge - there are a couple of other SQL challenges on this blog.

Postgres certainly seems to offer features/funtions that make this problem seem easy to solve, based on the solution that you offered.  

If I recall correctly, I thought that one of Postgres greatest asset was its ability to nearly behave as a drop-in replacement for Oracle Database.  Postgres ability to select rows without specifying a datasource is interesting, as is its function to calculate factorials.]]></description>
		<content:encoded><![CDATA[<p>Morgan,</p>
<p>Thank you for offering a solution to this SQL challenge &#8211; there are a couple of other SQL challenges on this blog.</p>
<p>Postgres certainly seems to offer features/funtions that make this problem seem easy to solve, based on the solution that you offered.  </p>
<p>If I recall correctly, I thought that one of Postgres greatest asset was its ability to nearly behave as a drop-in replacement for Oracle Database.  Postgres ability to select rows without specifying a datasource is interesting, as is its function to calculate factorials.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morgan</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-5249</link>
		<dc:creator><![CDATA[Morgan]]></dc:creator>
		<pubDate>Sun, 10 Feb 2013 17:56:11 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-5249</guid>
		<description><![CDATA[Neat post!  :)  I was able to solve it in a few minutes with this query (using postgres):

select x,y,factorial(x+y-2)/(factorial(x-1)*factorial(y-1)) as value from (select x,generate_series(1,8) as y from (select generate_series(1,8) as x) as s) as a group by x,y order by value;]]></description>
		<content:encoded><![CDATA[<p>Neat post!  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I was able to solve it in a few minutes with this query (using postgres):</p>
<p>select x,y,factorial(x+y-2)/(factorial(x-1)*factorial(y-1)) as value from (select x,generate_series(1,8) as y from (select generate_series(1,8) as x) as s) as a group by x,y order by value;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4891</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Tue, 21 Aug 2012 10:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4891</guid>
		<description><![CDATA[Peter,

Sorry for the delay in responding.  Very nice solution with the MODEL clause.  I suspected that there was an elegant solution to the problem using the MODEL clause, but I have not worked with it often enough to put the solution together from the beginning to the end.]]></description>
		<content:encoded><![CDATA[<p>Peter,</p>
<p>Sorry for the delay in responding.  Very nice solution with the MODEL clause.  I suspected that there was an elegant solution to the problem using the MODEL clause, but I have not worked with it often enough to put the solution together from the beginning to the end.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter van der Zwan</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4889</link>
		<dc:creator><![CDATA[Peter van der Zwan]]></dc:creator>
		<pubDate>Fri, 17 Aug 2012 15:22:51 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4889</guid>
		<description><![CDATA[Hi,

Here is another solutionusing the model clause:
&lt;pre&gt;
with m as
  (select
    *
  from
    dual
  model
  ignore nav
  dimension by (1 x, 1 y)
  measures (1 m)
  rules
    (
    m[for x from 1 to 8 increment 1,1] = 1
    ,m[1, for y from 1 to 8 increment 1] = 1
    ,m[for x from 2 to 8 increment 1, for y from 2 to 8 increment 1] =  m[cv(x)-1,cv(y)] + m[cv(x), cv(y) -1]
    )
  )
select
  *
from
  m
pivot (sum(m) for x in (&#039;1&#039;, &#039;2&#039;, &#039;3&#039;,&#039;4&#039; ,&#039;5&#039; ,&#039;6&#039; ,&#039;7&#039; ,&#039;8&#039;))
order by
  y;
&lt;/pre&gt;
The result is below:
&lt;pre&gt;
Y &#039;1&#039; &#039;2&#039; &#039;3&#039; &#039;4&#039; &#039;5&#039; &#039;6&#039; &#039;7&#039; &#039;8&#039;
- --- --- --- --- --- --- --- ---
1   1   1   1   1   1   1   1   1 
2   1   2   3   4   5   6   7   8 
3   1   3   6  10  15  21  28  36 
4   1   4  10  20  35  56  84 120 
5   1   5  15  35  70 126 210 330 
6   1   6  21  56 126 252 462 792 
7   1   7  28  84 210 462 924 1716 
8   1   8  36 120 330 792 1716 3432 

 8 rows selected 

&lt;/pre&gt;

Regards,

Peter]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Here is another solutionusing the model clause:</p>
<pre>
with m as
  (select
    *
  from
    dual
  model
  ignore nav
  dimension by (1 x, 1 y)
  measures (1 m)
  rules
    (
    m[for x from 1 to 8 increment 1,1] = 1
    ,m[1, for y from 1 to 8 increment 1] = 1
    ,m[for x from 2 to 8 increment 1, for y from 2 to 8 increment 1] =  m[cv(x)-1,cv(y)] + m[cv(x), cv(y) -1]
    )
  )
select
  *
from
  m
pivot (sum(m) for x in ('1', '2', '3','4' ,'5' ,'6' ,'7' ,'8'))
order by
  y;
</pre>
<p>The result is below:</p>
<pre>
Y '1' '2' '3' '4' '5' '6' '7' '8'
- --- --- --- --- --- --- --- ---
1   1   1   1   1   1   1   1   1 
2   1   2   3   4   5   6   7   8 
3   1   3   6  10  15  21  28  36 
4   1   4  10  20  35  56  84 120 
5   1   5  15  35  70 126 210 330 
6   1   6  21  56 126 252 462 792 
7   1   7  28  84 210 462 924 1716 
8   1   8  36 120 330 792 1716 3432 

 8 rows selected 

</pre>
<p>Regards,</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pascal matrix SQL puzzle solution &#8211; All Things Oracle</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4761</link>
		<dc:creator><![CDATA[Pascal matrix SQL puzzle solution &#8211; All Things Oracle]]></dc:creator>
		<pubDate>Wed, 20 Jun 2012 10:56:35 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4761</guid>
		<description><![CDATA[[...] with the solutions to my little problem of generating a symmetric Pascal matrix using SQL. Charles Hooper in particular has provided some very nice commentary on the problem, complete with diagrams and 2 alternative [...]]]></description>
		<content:encoded><![CDATA[<p>[...] with the solutions to my little problem of generating a symmetric Pascal matrix using SQL. Charles Hooper in particular has provided some very nice commentary on the problem, complete with diagrams and 2 alternative [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4749</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 18 Jun 2012 01:14:49 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4749</guid>
		<description><![CDATA[Mrpy,

An interesting looking SQL statement.  Unfortunately, it appears that part of your SQL statement disappeared:
&lt;pre&gt;
ERROR at line 5:
ORA-00920: invalid relational operator
&lt;/pre&gt;

Unfortunately, less than and greater than signs are HTML formatting keywords.  As such, it is necessary to replace less than (&lt;) and greater than (&gt;) signs in comments with the appropriate HTML equivalent - see the bottom of the blue section at the right.

I am looking forward to seeing this full SQL statement.]]></description>
		<content:encoded><![CDATA[<p>Mrpy,</p>
<p>An interesting looking SQL statement.  Unfortunately, it appears that part of your SQL statement disappeared:</p>
<pre>
ERROR at line 5:
ORA-00920: invalid relational operator
</pre>
<p>Unfortunately, less than and greater than signs are HTML formatting keywords.  As such, it is necessary to replace less than (&lt;) and greater than (&gt;) signs in comments with the appropriate HTML equivalent &#8211; see the bottom of the blue section at the right.</p>
<p>I am looking forward to seeing this full SQL statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mrpy</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4748</link>
		<dc:creator><![CDATA[mrpy]]></dc:creator>
		<pubDate>Sun, 17 Jun 2012 22:39:44 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4748</guid>
		<description><![CDATA[select * from (
  select *
  from 
    (select level x from dual connect by level&lt;=8), 
    (select level y from dual connect by level1, y&gt;1] = s[cv(x)-1, cv()] + s[cv(), cv(y)-1] 
  )
)
pivot (max(s) for x in (1,2,3,4,5,6,7,8))
order by 1]]></description>
		<content:encoded><![CDATA[<p>select * from (<br />
  select *<br />
  from<br />
    (select level x from dual connect by level&lt;=8),<br />
    (select level y from dual connect by level1, y&gt;1] = s[cv(x)-1, cv()] + s[cv(), cv(y)-1]<br />
  )<br />
)<br />
pivot (max(s) for x in (1,2,3,4,5,6,7,8))<br />
order by 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oracle Musings &#187; Pascal matrix SQL puzzle solution</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4747</link>
		<dc:creator><![CDATA[Oracle Musings &#187; Pascal matrix SQL puzzle solution]]></dc:creator>
		<pubDate>Sat, 16 Jun 2012 23:35:36 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4747</guid>
		<description><![CDATA[[...] with the solutions to my little problem of generating a symmetric Pascal matrix using SQL. Charles Hooper in particular has provided some very nice commentary on the problem, complete with diagrams and 2 alternative [...]]]></description>
		<content:encoded><![CDATA[<p>[...] with the solutions to my little problem of generating a symmetric Pascal matrix using SQL. Charles Hooper in particular has provided some very nice commentary on the problem, complete with diagrams and 2 alternative [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4746</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Sat, 16 Jun 2012 12:02:37 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4746</guid>
		<description><![CDATA[Raj,

That is impressive.  

I have not worked with the model clause, but had hoped that someone would post an example using that clause.  It appears that the model clause is quite powerful, allowing the specification of formulas that are similar to the formulas that I used in Microsoft Excel at the start of this article.

Thanks again for posting the example.]]></description>
		<content:encoded><![CDATA[<p>Raj,</p>
<p>That is impressive.  </p>
<p>I have not worked with the model clause, but had hoped that someone would post an example using that clause.  It appears that the model clause is quite powerful, allowing the specification of formulas that are similar to the formulas that I used in Microsoft Excel at the start of this article.</p>
<p>Thanks again for posting the example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: raj</title>
		<link>http://hoopercharles.wordpress.com/2012/06/14/sql-challenges/#comment-4744</link>
		<dc:creator><![CDATA[raj]]></dc:creator>
		<pubDate>Sat, 16 Jun 2012 11:20:44 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=6389#comment-4744</guid>
		<description><![CDATA[Hi Charles,

Apologies.  I didn&#039;t read the guidelines before posting the comments.  My bad.  I think I got it right this time.

&lt;pre&gt;
SQL&gt; l
  1  select
  2  col_1,
  3  col_2,
  4  col_3,
  5  col_4,
  6  col_5,
  7  col_6,
  8  col_7,
  9  col_8
 10  from
 11  dual connect by level &lt;= 8
 12  model
 13  dimension by (level as lev)
 14  measures (
 15  1 as col_1, 1 as col_2, 1 as col_3, 1 as col_4, 1 as col_5, 1 as col_6, 1 as col_7, 1 as col_8)
 16  rules
 17  (
 18  col_1[any] = 1,
 19  col_2[lev &gt; 1] = col_1[cv()] + col_2[cv(lev) - 1] ,
 20  col_3[lev &gt; 1] = col_2[cv()] + col_3[cv(lev) - 1] ,
 21  col_4[lev &gt; 1] = col_3[cv()] + col_4[cv(lev) - 1] ,
 22  col_5[lev &gt; 1] = col_4[cv()] + col_5[cv(lev) - 1] ,
 23  col_6[lev &gt; 1] = col_5[cv()] + col_6[cv(lev) - 1] ,
 24  col_7[lev &gt; 1] = col_6[cv()] + col_7[cv(lev) - 1] ,
 25  col_8[lev &gt; 1] = col_7[cv()] + col_8[cv(lev) - 1]
 26* )
SQL&gt; /

     COL_1      COL_2      COL_3      COL_4      COL_5      COL_6      COL_7      COL_8
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
         1          1          1          1          1          1          1          1
         1          2          3          4          5          6          7          8
         1          3          6         10         15         21         28         36
         1          4         10         20         35         56         84        120
         1          5         15         35         70        126        210        330
         1          6         21         56        126        252        462        792
         1          7         28         84        210        462        924       1716
         1          8         36        120        330        792       1716       3432

8 rows selected.
&lt;/pre&gt;

Thanks

Raj]]></description>
		<content:encoded><![CDATA[<p>Hi Charles,</p>
<p>Apologies.  I didn&#8217;t read the guidelines before posting the comments.  My bad.  I think I got it right this time.</p>
<pre>
SQL&gt; l
  1  select
  2  col_1,
  3  col_2,
  4  col_3,
  5  col_4,
  6  col_5,
  7  col_6,
  8  col_7,
  9  col_8
 10  from
 11  dual connect by level &lt;= 8
 12  model
 13  dimension by (level as lev)
 14  measures (
 15  1 as col_1, 1 as col_2, 1 as col_3, 1 as col_4, 1 as col_5, 1 as col_6, 1 as col_7, 1 as col_8)
 16  rules
 17  (
 18  col_1[any] = 1,
 19  col_2[lev &gt; 1] = col_1[cv()] + col_2[cv(lev) - 1] ,
 20  col_3[lev &gt; 1] = col_2[cv()] + col_3[cv(lev) - 1] ,
 21  col_4[lev &gt; 1] = col_3[cv()] + col_4[cv(lev) - 1] ,
 22  col_5[lev &gt; 1] = col_4[cv()] + col_5[cv(lev) - 1] ,
 23  col_6[lev &gt; 1] = col_5[cv()] + col_6[cv(lev) - 1] ,
 24  col_7[lev &gt; 1] = col_6[cv()] + col_7[cv(lev) - 1] ,
 25  col_8[lev &gt; 1] = col_7[cv()] + col_8[cv(lev) - 1]
 26* )
SQL&gt; /

     COL_1      COL_2      COL_3      COL_4      COL_5      COL_6      COL_7      COL_8
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
         1          1          1          1          1          1          1          1
         1          2          3          4          5          6          7          8
         1          3          6         10         15         21         28         36
         1          4         10         20         35         56         84        120
         1          5         15         35         70        126        210        330
         1          6         21         56        126        252        462        792
         1          7         28         84        210        462        924       1716
         1          8         36        120        330        792       1716       3432

8 rows selected.
</pre>
<p>Thanks</p>
<p>Raj</p>
]]></content:encoded>
	</item>
</channel>
</rss>
