<?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 solve the Coin Combinations Puzzle in SQL</title>
	<atom:link href="http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/</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: newkid</title>
		<link>http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/comment-page-1/#comment-287</link>
		<dc:creator>newkid</dc:creator>
		<pubDate>Mon, 28 Jun 2010 19:27:31 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/#comment-287</guid>
		<description>&lt;pre&gt;
SELECT c1 .cents&#124;&#124;&#039;*&#039;&#124;&#124;c1 .cnt
       &#124;&#124;&#039;+&#039;&#124;&#124;c5 .cents&#124;&#124;&#039;*&#039;&#124;&#124;c5 .cnt
       &#124;&#124;&#039;+&#039;&#124;&#124;c10.cents&#124;&#124;&#039;*&#039;&#124;&#124;c10.cnt
       &#124;&#124;&#039;+&#039;&#124;&#124;c25.cents&#124;&#124;&#039;*&#039;&#124;&#124;c25.cnt
       &#124;&#124;&#039;+&#039;&#124;&#124;c50.cents&#124;&#124;&#039;*&#039;&#124;&#124;c50.cnt
  FROM (SELECT 1  cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=100)  c1
      ,(SELECT 5  cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=20 )  c5
      ,(SELECT 10 cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=10 )  c10
      ,(SELECT 25 cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=4  )  c25
      ,(SELECT 50 cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=2  )  c50
WHERE c1 .cents*c1 .cnt
     +c5 .cents*c5 .cnt
     +c10.cents*c10.cnt
     +c25.cents*c25.cnt
     +c50.cents*c50.cnt=100;

recursive WITH in 11GR2:
WITH coins AS (
  SELECT 1 cents FROM DUAL
  UNION ALL SELECT 5 cents FROM DUAL
  UNION ALL SELECT 10 cents FROM DUAL
  UNION ALL SELECT 25 cents FROM DUAL
  UNION ALL SELECT 50 cents FROM DUAL
  )
,t(c1,c5,c10,c25,c50,cents,total_val) AS (
SELECT DECODE(c.cents,1,1,0)
      ,DECODE(c.cents,5,1,0)          
      ,DECODE(c.cents,10,1,0)          
      ,DECODE(c.cents,25,1,0)          
      ,DECODE(c.cents,50,1,0)          
      ,cents 
      ,cents 
  FROM coins c
UNION ALL
SELECT c1 + DECODE(c.cents,1,1,0)
      ,c5 + DECODE(c.cents,5,1,0)          
      ,c10+ DECODE(c.cents,10,1,0)          
      ,c25+ DECODE(c.cents,25,1,0)          
      ,c50+ DECODE(c.cents,50,1,0)          
      ,c.cents
      ,t.total_val + c.cents
  FROM t, coins c
WHERE t.total_val + c.cents&lt;=100 AND t.cents&lt;=c.cents
)
SELECT * FROM t WHERE total_val=100;

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
SELECT c1 .cents||'*'||c1 .cnt
       ||'+'||c5 .cents||'*'||c5 .cnt
       ||'+'||c10.cents||'*'||c10.cnt
       ||'+'||c25.cents||'*'||c25.cnt
       ||'+'||c50.cents||'*'||c50.cnt
  FROM (SELECT 1  cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=100)  c1
      ,(SELECT 5  cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=20 )  c5
      ,(SELECT 10 cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=10 )  c10
      ,(SELECT 25 cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=4  )  c25
      ,(SELECT 50 cents, ROWNUM-1 cnt FROM DUAL CONNECT BY ROWNUM-1&lt;=2  )  c50
WHERE c1 .cents*c1 .cnt
     +c5 .cents*c5 .cnt
     +c10.cents*c10.cnt
     +c25.cents*c25.cnt
     +c50.cents*c50.cnt=100;

recursive WITH in 11GR2:
WITH coins AS (
  SELECT 1 cents FROM DUAL
  UNION ALL SELECT 5 cents FROM DUAL
  UNION ALL SELECT 10 cents FROM DUAL
  UNION ALL SELECT 25 cents FROM DUAL
  UNION ALL SELECT 50 cents FROM DUAL
  )
,t(c1,c5,c10,c25,c50,cents,total_val) AS (
SELECT DECODE(c.cents,1,1,0)
      ,DECODE(c.cents,5,1,0)
      ,DECODE(c.cents,10,1,0)
      ,DECODE(c.cents,25,1,0)
      ,DECODE(c.cents,50,1,0)
      ,cents
      ,cents
  FROM coins c
UNION ALL
SELECT c1 + DECODE(c.cents,1,1,0)
      ,c5 + DECODE(c.cents,5,1,0)
      ,c10+ DECODE(c.cents,10,1,0)
      ,c25+ DECODE(c.cents,25,1,0)
      ,c50+ DECODE(c.cents,50,1,0)
      ,c.cents
      ,t.total_val + c.cents
  FROM t, coins c
WHERE t.total_val + c.cents&lt;=100 AND t.cents&lt;=c.cents
)
SELECT * FROM t WHERE total_val=100;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Zhou</title>
		<link>http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/comment-page-1/#comment-232</link>
		<dc:creator>Frank Zhou</dc:creator>
		<pubDate>Mon, 04 Feb 2008 19:25:45 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/#comment-232</guid>
		<description>Nsp,
There is really nothing special about my thought process.
Everybody can becomes a good problem solver, if they are really enjoy doing it. Most of the time I  have solved the problem using the following approach.

1) Learn and understand every new SQL features/functions in the manual    
2) Thinking outside of the box and attack the problem from different directions.
     Don&#039;t limit your mind set to the conventional approach.
3) Draw diagrams if needed.
4) Implement the solution in layers,
  Write the inline view on top of each other as if you are implementing a function.

Frank</description>
		<content:encoded><![CDATA[<p>Nsp,<br />
There is really nothing special about my thought process.<br />
Everybody can becomes a good problem solver, if they are really enjoy doing it. Most of the time I  have solved the problem using the following approach.</p>
<p>1) Learn and understand every new SQL features/functions in the manual<br />
2) Thinking outside of the box and attack the problem from different directions.<br />
     Don&#8217;t limit your mind set to the conventional approach.<br />
3) Draw diagrams if needed.<br />
4) Implement the solution in layers,<br />
  Write the inline view on top of each other as if you are implementing a function.</p>
<p>Frank</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nsp</title>
		<link>http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/comment-page-1/#comment-231</link>
		<dc:creator>nsp</dc:creator>
		<pubDate>Mon, 04 Feb 2008 12:18:18 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2008/02/01/how-to-solve-the-coin-combinations-puzzle-in-sql/#comment-231</guid>
		<description>Frank,
Seriuosly, tell me how do you think of these solutions.
I would die to learn your thought process.
Believe me, it would take (at least) a week for me to figure out how you managed to build this query (and many others).</description>
		<content:encoded><![CDATA[<p>Frank,<br />
Seriuosly, tell me how do you think of these solutions.<br />
I would die to learn your thought process.<br />
Believe me, it would take (at least) a week for me to figure out how you managed to build this query (and many others).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

