<?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: Making up records in SQL Queries &#8211; Table Functions and 10g Model clause</title>
	<atom:link href="http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=making-up-records-in-sql-queries-table-functions-and-10g-model-clause</link>
	<description></description>
	<lastBuildDate>Fri, 12 Apr 2013 10:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: drkalucard</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1178</link>
		<dc:creator>drkalucard</dc:creator>
		<pubDate>Tue, 05 Sep 2006 08:42:50 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1178</guid>
		<description><![CDATA[what do you think about this?
select Job, DECODE(DEPTNO,10,sum(SAL), NULL) Dept 10,
               DECODE(DEPTNO,20,sum(SAL), NULL) Dept 20,
	       DECODE(DEPTNO,30,sum(SAL), NULL) Dept 10,
               sum(SAL) Total
from EMP
group by Job;]]></description>
		<content:encoded><![CDATA[<p>what do you think about this?<br />
select Job, DECODE(DEPTNO,10,sum(SAL), NULL) Dept 10,<br />
               DECODE(DEPTNO,20,sum(SAL), NULL) Dept 20,<br />
	       DECODE(DEPTNO,30,sum(SAL), NULL) Dept 10,<br />
               sum(SAL) Total<br />
from EMP<br />
group by Job;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1177</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Thu, 13 Apr 2006 20:51:00 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1177</guid>
		<description><![CDATA[I am trying to create a view that shows the total of overdue people by,  less than 30 days, 31 to 59days, and over 60 days overdue.
What is wrong with my code.

CREATE OR REPLACE VIEW  csu_status_date_vu
 (category, less than 30 days, 31-59 days, 60 days and greater)

AS  SELECT  ass_attribute9,  effective_start_date

FROM   PER_ALL_ASSIGNMENTS_F

WHERE (SELECT SUM (CASE
               WHEN  effective_start_date &gt; TRUNC (SYSDATE - 30)
                  THEN 1
               ELSE 0
            END) &quot;less than 30 days&quot;,
       SUM (CASE
               WHEN effective_start_date = TRUNC (SYSDATE - 59)
                  THEN 1
               ELSE 0
            END) &quot;31 -59 days&quot;,
       SUM (CASE
               WHEN  effective_start_date]]></description>
		<content:encoded><![CDATA[<p>I am trying to create a view that shows the total of overdue people by,  less than 30 days, 31 to 59days, and over 60 days overdue.<br />
What is wrong with my code.</p>
<p>CREATE OR REPLACE VIEW  csu_status_date_vu<br />
 (category, less than 30 days, 31-59 days, 60 days and greater)</p>
<p>AS  SELECT  ass_attribute9,  effective_start_date</p>
<p>FROM   PER_ALL_ASSIGNMENTS_F</p>
<p>WHERE (SELECT SUM (CASE<br />
               WHEN  effective_start_date &gt; TRUNC (SYSDATE &#8211; 30)<br />
                  THEN 1<br />
               ELSE 0<br />
            END) &#8220;less than 30 days&#8221;,<br />
       SUM (CASE<br />
               WHEN effective_start_date = TRUNC (SYSDATE &#8211; 59)<br />
                  THEN 1<br />
               ELSE 0<br />
            END) &#8220;31 -59 days&#8221;,<br />
       SUM (CASE<br />
               WHEN  effective_start_date</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Andrews</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1176</link>
		<dc:creator>Tony Andrews</dc:creator>
		<pubDate>Thu, 15 Sep 2005 13:12:45 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1176</guid>
		<description><![CDATA[Re the pivot query, isn&#039;t this a whole lot simpler? :-

SQL&gt; select job
  2  ,      sum(case when deptno=10 then sal else 0 end) dept10
  3  ,      sum(case when deptno=20 then sal else 0 end) dept20
  4  ,      sum(case when deptno=30 then sal else 0 end) dept30
  5  ,      sum(sal) total
  6  from emp
  7  group by job;

JOB           DEPT10     DEPT20     DEPT30      TOTAL
--------- ---------- ---------- ---------- ----------
ANALYST            0       6000          0       6000
CLERK           1300       1900        950       4150
MANAGER         2450       2975       2850       8275
PRESIDENT       5000          0          0       5000
SALESMAN           0          0       5600       5600]]></description>
		<content:encoded><![CDATA[<p>Re the pivot query, isn&#8217;t this a whole lot simpler? :-</p>
<p>SQL> select job<br />
  2  ,      sum(case when deptno=10 then sal else 0 end) dept10<br />
  3  ,      sum(case when deptno=20 then sal else 0 end) dept20<br />
  4  ,      sum(case when deptno=30 then sal else 0 end) dept30<br />
  5  ,      sum(sal) total<br />
  6  from emp<br />
  7  group by job;</p>
<p>JOB           DEPT10     DEPT20     DEPT30      TOTAL<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
ANALYST            0       6000          0       6000<br />
CLERK           1300       1900        950       4150<br />
MANAGER         2450       2975       2850       8275<br />
PRESIDENT       5000          0          0       5000<br />
SALESMAN           0          0       5600       5600</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1174</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Thu, 16 Dec 2004 15:16:44 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1174</guid>
		<description><![CDATA[OK, using the SQL MODEL clause (only in Oracle 10g I am afraid) I found the near perfect solution. Its result looks as follows:
&lt;code&gt;JOB       DEPT10     DEPT20     DEPT30     GRAND_TOTAL
--------- ---------- ---------- ---------- -----------
CLERK     1300       1900       950               4150
SALESMAN                        5600              5600
PRESIDENT 5000                                    5000
MANAGER   2450       2975       2850              8275
ANALYST              6000                         6000&lt;/code&gt;

The query itself:
&lt;code&gt;
select job
,      dept10
,      dept20
,      dept30
,      grand_total
from   (select distinct deptno,  job, sum(sal) OVER ( PARTITION BY deptno, job) sumsal , sum(sal) over( partition by job) sumjob from emp )
model
  return updated rows
  partition by (job)
  dimension by (deptno)
  measures (sumsal,   lpad(&#039; &#039;,10) dept10, lpad(&#039; &#039;,10) dept20, lpad(&#039; &#039;,10) dept30 , sumjob grand_total)
  rules upsert
  (
      dept10 [0] = sumsal [10]
    , dept20 [0] = sumsal [20]
    , dept30 [0] = sumsal [30]
    , grand_total [0] = max(grand_total) [ANY]
  )
&lt;/code&gt;

For more insight and an explanation, see this post &lt;a href=&quot;http://technology.amis.nl/blog/index.php?p=300&quot;  rel=&quot;nofollow&quot;&gt;Pivoting in SQL using the 10g Model Clause&lt;/a&gt;]]></description>
		<content:encoded><![CDATA[<p>OK, using the SQL MODEL clause (only in Oracle 10g I am afraid) I found the near perfect solution. Its result looks as follows:<br />
<code>JOB       DEPT10     DEPT20     DEPT30     GRAND_TOTAL<br />
--------- ---------- ---------- ---------- -----------<br />
CLERK     1300       1900       950               4150<br />
SALESMAN                        5600              5600<br />
PRESIDENT 5000                                    5000<br />
MANAGER   2450       2975       2850              8275<br />
ANALYST              6000                         6000</code></p>
<p>The query itself:<br />
<code><br />
select job<br />
,      dept10<br />
,      dept20<br />
,      dept30<br />
,      grand_total<br />
from   (select distinct deptno,  job, sum(sal) OVER ( PARTITION BY deptno, job) sumsal , sum(sal) over( partition by job) sumjob from emp )<br />
model<br />
  return updated rows<br />
  partition by (job)<br />
  dimension by (deptno)<br />
  measures (sumsal,   lpad(' ',10) dept10, lpad(' ',10) dept20, lpad(' ',10) dept30 , sumjob grand_total)<br />
  rules upsert<br />
  (<br />
      dept10 [0] = sumsal [10]<br />
    , dept20 [0] = sumsal [20]<br />
    , dept30 [0] = sumsal [30]<br />
    , grand_total [0] = max(grand_total) [ANY]<br />
  )<br />
</code></p>
<p>For more insight and an explanation, see this post <a href="http://technology.amis.nl/blog/index.php?p=300"  rel="nofollow">Pivoting in SQL using the 10g Model Clause</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1173</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Wed, 08 Dec 2004 12:19:52 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1173</guid>
		<description><![CDATA[OK, I missed the proper pivot. By replacing job and deptno in the above query we get the following result:
&lt;pre&gt;JOB       SAL_SUM1             SAL_SUM2             SAL_SUM3
--------- -------------------- -------------------- -------------
ANALYST   10:                  20: 6000             30:
CLERK     10: 1300             20: 1900             30: 950
MANAGER   10: 2450             20: 2975             30: 2850
PRESIDENT 10: 5000             20:                  30:
SALESMAN  10:                  20:                  30: 5600            &lt;/pre&gt;

The query now looks as follows:&lt;pre&gt;select job
,      substr(sal_sum1, 1, 20) sal_sum1
,      substr(sal_sum2, 1, 20) sal_sum2
,      substr(sal_sum3, 1, 20) sal_sum3
,      substr(sal_sum4, 1, 20) sal_sum4
,      substr(sal_sum5, 1, 20) sal_sum5
,      substr(sal_sum6, 1, 20) sal_sum6
from ( select job
       ,      deptno&#124;&#124;&#039;: &#039;&#124;&#124;sal_sum sal_sum1
       ,      lead(deptno,1) over (partition by job order by deptno)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,1) over (partition by job order by deptno) sal_sum2
       ,      lead(deptno,2) over (partition by job order by deptno)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,2) over (partition by job order by deptno) sal_sum3
       ,      lead(deptno,3) over (partition by job order by deptno)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,3) over (partition by job order by deptno) sal_sum4
       ,      lead(deptno,4) over (partition by job order by deptno)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,4) over (partition by job order by deptno) sal_sum5
       ,      lead(deptno,5) over (partition by job order by deptno)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,5) over (partition by job order by deptno) sal_sum6
       ,      row_number() over (partition by job order by deptno) rnk
       from ( select distinct
                     job
              ,      deptnos.deptno
              ,      sum(sal) over (partition by emp.deptno, job) sal_sum
              from   emp partition by (job)
                     right outer join
                     (select distinct deptno from emp) deptnos
                     on (emp.deptno = deptnos.deptno)
              order
              by     job
              ,      deptno
            )
     )
where rnk = 1 &lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>OK, I missed the proper pivot. By replacing job and deptno in the above query we get the following result:</p>
<pre class="wp-code-highlight prettyprint">JOB       SAL_SUM1             SAL_SUM2             SAL_SUM3
--------- -------------------- -------------------- -------------
ANALYST   10:                  20: 6000             30:
CLERK     10: 1300             20: 1900             30: 950
MANAGER   10: 2450             20: 2975             30: 2850
PRESIDENT 10: 5000             20:                  30:
SALESMAN  10:                  20:                  30: 5600            </pre>
<p>The query now looks as follows:
<pre class="wp-code-highlight prettyprint">select job
,      substr(sal_sum1, 1, 20) sal_sum1
,      substr(sal_sum2, 1, 20) sal_sum2
,      substr(sal_sum3, 1, 20) sal_sum3
,      substr(sal_sum4, 1, 20) sal_sum4
,      substr(sal_sum5, 1, 20) sal_sum5
,      substr(sal_sum6, 1, 20) sal_sum6
from ( select job
       ,      deptno||&#039;: &#039;||sal_sum sal_sum1
       ,      lead(deptno,1) over (partition by job order by deptno)
              ||&#039;: &#039;||lead(sal_sum,1) over (partition by job order by deptno) sal_sum2
       ,      lead(deptno,2) over (partition by job order by deptno)
              ||&#039;: &#039;||lead(sal_sum,2) over (partition by job order by deptno) sal_sum3
       ,      lead(deptno,3) over (partition by job order by deptno)
              ||&#039;: &#039;||lead(sal_sum,3) over (partition by job order by deptno) sal_sum4
       ,      lead(deptno,4) over (partition by job order by deptno)
              ||&#039;: &#039;||lead(sal_sum,4) over (partition by job order by deptno) sal_sum5
       ,      lead(deptno,5) over (partition by job order by deptno)
              ||&#039;: &#039;||lead(sal_sum,5) over (partition by job order by deptno) sal_sum6
       ,      row_number() over (partition by job order by deptno) rnk
       from ( select distinct
                     job
              ,      deptnos.deptno
              ,      sum(sal) over (partition by emp.deptno, job) sal_sum
              from   emp partition by (job)
                     right outer join
                     (select distinct deptno from emp) deptnos
                     on (emp.deptno = deptnos.deptno)
              order
              by     job
              ,      deptno
            )
     )
where rnk = 1 </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1172</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Wed, 08 Dec 2004 12:16:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1172</guid>
		<description><![CDATA[Maybe a better, more generic solution with less hard-coding and less coding in general - though only suitable for Oracle 10g because of the partion by clause in the outer join expression - would render the following result:

&lt;pre&gt; DEPTNO SAL_SUM1             SAL_SUM2             SAL_SUM3             SAL_SUM4             SAL_SUM5             SAL_SUM6
------- -------------------- -------------------- -------------------- -------------------- -----
     10 ANALYST:             CLERK: 1300          MANAGER: 2450        PRESIDENT: 5000      SALESMAN:            :
     20 ANALYST: 6000        CLERK: 1900          MANAGER: 2975        PRESIDENT:           SALESMAN:            :
     30 ANALYST:             CLERK: 950           MANAGER: 2850        PRESIDENT:           SALESMAN: 5600       :&lt;/pre&gt;

The code used to produce this result:
&lt;pre&gt;select deptno
,      substr(sal_sum1, 1, 20) sal_sum1
,      substr(sal_sum2, 1, 20) sal_sum2
,      substr(sal_sum3, 1, 20) sal_sum3
,      substr(sal_sum4, 1, 20) sal_sum4
,      substr(sal_sum5, 1, 20) sal_sum5
,      substr(sal_sum6, 1, 20) sal_sum6
from ( select deptno
       ,      job&#124;&#124;&#039;: &#039;&#124;&#124;sal_sum sal_sum1
       ,      lead(job,1) over (partition by deptno order by job)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,1) over (partition by deptno order by job) sal_sum2
       ,      lead(job,2) over (partition by deptno order by job)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,2) over (partition by deptno order by job) sal_sum3
       ,      lead(job,3) over (partition by deptno order by job)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,3) over (partition by deptno order by job) sal_sum4
       ,      lead(job,4) over (partition by deptno order by job)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,4) over (partition by deptno order by job) sal_sum5
       ,      lead(job,5) over (partition by deptno order by job)
              &#124;&#124;&#039;: &#039;&#124;&#124;lead(sal_sum,5) over (partition by deptno order by job) sal_sum6
       ,      row_number() over (partition by deptno order by job) rnk
       from ( select distinct
                     deptno
              ,      jobs.job
              ,      sum(sal) over (partition by emp.job, deptno) sal_sum
              from   emp partition by (deptno)
                     right outer join
                     (select distinct job from emp) jobs
                     on (emp.job = jobs.job)
              order
              by     deptno
              ,      job
            )
     )
where rnk = 1&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Maybe a better, more generic solution with less hard-coding and less coding in general &#8211; though only suitable for Oracle 10g because of the partion by clause in the outer join expression &#8211; would render the following result:</p>
<pre class="wp-code-highlight prettyprint"> DEPTNO SAL_SUM1             SAL_SUM2             SAL_SUM3             SAL_SUM4             SAL_SUM5             SAL_SUM6
------- -------------------- -------------------- -------------------- -------------------- -----
     10 ANALYST:             CLERK: 1300          MANAGER: 2450        PRESIDENT: 5000      SALESMAN:            :
     20 ANALYST: 6000        CLERK: 1900          MANAGER: 2975        PRESIDENT:           SALESMAN:            :
     30 ANALYST:             CLERK: 950           MANAGER: 2850        PRESIDENT:           SALESMAN: 5600       :</pre>
<p>The code used to produce this result:</p>
<pre class="wp-code-highlight prettyprint">select deptno
,      substr(sal_sum1, 1, 20) sal_sum1
,      substr(sal_sum2, 1, 20) sal_sum2
,      substr(sal_sum3, 1, 20) sal_sum3
,      substr(sal_sum4, 1, 20) sal_sum4
,      substr(sal_sum5, 1, 20) sal_sum5
,      substr(sal_sum6, 1, 20) sal_sum6
from ( select deptno
       ,      job||&#039;: &#039;||sal_sum sal_sum1
       ,      lead(job,1) over (partition by deptno order by job)
              ||&#039;: &#039;||lead(sal_sum,1) over (partition by deptno order by job) sal_sum2
       ,      lead(job,2) over (partition by deptno order by job)
              ||&#039;: &#039;||lead(sal_sum,2) over (partition by deptno order by job) sal_sum3
       ,      lead(job,3) over (partition by deptno order by job)
              ||&#039;: &#039;||lead(sal_sum,3) over (partition by deptno order by job) sal_sum4
       ,      lead(job,4) over (partition by deptno order by job)
              ||&#039;: &#039;||lead(sal_sum,4) over (partition by deptno order by job) sal_sum5
       ,      lead(job,5) over (partition by deptno order by job)
              ||&#039;: &#039;||lead(sal_sum,5) over (partition by deptno order by job) sal_sum6
       ,      row_number() over (partition by deptno order by job) rnk
       from ( select distinct
                     deptno
              ,      jobs.job
              ,      sum(sal) over (partition by emp.job, deptno) sal_sum
              from   emp partition by (deptno)
                     right outer join
                     (select distinct job from emp) jobs
                     on (emp.job = jobs.job)
              order
              by     deptno
              ,      job
            )
     )
where rnk = 1</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas Jellema</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1171</link>
		<dc:creator>Lucas Jellema</dc:creator>
		<pubDate>Wed, 24 Nov 2004 08:50:37 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1171</guid>
		<description><![CDATA[I am not sure this is the most elegant solution, but it most certainly gives the matrix report you asked for:
&lt;code&gt;
JOB          DEPT10     DEPT20     DEPT30      TOTAL
-------- ---------- ---------- ---------- ----------
Clerks         1430       2090       1045       4565
Managers          0       2975       2850       5825
Salesmen          0          0       3100       3100
&lt;/code&gt;
&lt;code&gt;
select case dn.n
       when 1
       then  &#039;Clerks&#039;
       when 2
       then  &#039;Managers&#039;
       when 3
       then  &#039;Salesmen&#039;
       else  null
       end   job
, max( case
       when rn=1 and dn.n = 1
       then  clerks
       when rn=1 and dn.n = 2
       then  managers
       when rn=1 and dn.n = 3
       then  salesmen
       else  null
       end) dept10
, max( case
       when rn=2 and dn.n = 1
       then  clerks
       when rn=2 and dn.n = 2
       then  managers
       when rn=2 and dn.n = 3
       then  salesmen
       else  null
       end ) dept20
,  max(case
       when rn=3 and dn.n = 1
       then  clerks
       when rn=3 and dn.n = 2
       then  managers
       when rn=3 and dn.n = 3
       then  salesmen
       else  null
       end) dept30
,  sum(case
       when dn.n = 1
       then  clerks
       when dn.n = 2
       then  managers
       when dn.n = 3
       then  salesmen
       else  0
       end) total
from
(select deptno
,      row_number() over (order by deptno) rn
,      sum( case job
            when &#039;CLERK&#039;
            then sal
            else 0
            end
          ) clerks
,      sum( case job
            when &#039;MANAGER&#039;
            then sal
            else 0
            end
          ) Managers
,      sum( case job
            when &#039;SALESMAN&#039;
            then sal
            else 0
            end
          ) salesmen
from   emp
group
by     deptno
)
,   (select rownum n from emp where rownum&lt;4) dn
group
by     case dn.n
       when 1
       then  &#039;Clerks&#039;
       when 2
       then  &#039;Managers&#039;
       when 3
       then  &#039;Salesmen&#039;
       else  null
       end
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>I am not sure this is the most elegant solution, but it most certainly gives the matrix report you asked for:<br />
<code><br />
JOB          DEPT10     DEPT20     DEPT30      TOTAL<br />
-------- ---------- ---------- ---------- ----------<br />
Clerks         1430       2090       1045       4565<br />
Managers          0       2975       2850       5825<br />
Salesmen          0          0       3100       3100<br />
</code><br />
<code><br />
select case dn.n<br />
       when 1<br />
       then  'Clerks'<br />
       when 2<br />
       then  'Managers'<br />
       when 3<br />
       then  'Salesmen'<br />
       else  null<br />
       end   job<br />
, max( case<br />
       when rn=1 and dn.n = 1<br />
       then  clerks<br />
       when rn=1 and dn.n = 2<br />
       then  managers<br />
       when rn=1 and dn.n = 3<br />
       then  salesmen<br />
       else  null<br />
       end) dept10<br />
, max( case<br />
       when rn=2 and dn.n = 1<br />
       then  clerks<br />
       when rn=2 and dn.n = 2<br />
       then  managers<br />
       when rn=2 and dn.n = 3<br />
       then  salesmen<br />
       else  null<br />
       end ) dept20<br />
,  max(case<br />
       when rn=3 and dn.n = 1<br />
       then  clerks<br />
       when rn=3 and dn.n = 2<br />
       then  managers<br />
       when rn=3 and dn.n = 3<br />
       then  salesmen<br />
       else  null<br />
       end) dept30<br />
,  sum(case<br />
       when dn.n = 1<br />
       then  clerks<br />
       when dn.n = 2<br />
       then  managers<br />
       when dn.n = 3<br />
       then  salesmen<br />
       else  0<br />
       end) total<br />
from<br />
(select deptno<br />
,      row_number() over (order by deptno) rn<br />
,      sum( case job<br />
            when 'CLERK'<br />
            then sal<br />
            else 0<br />
            end<br />
          ) clerks<br />
,      sum( case job<br />
            when 'MANAGER'<br />
            then sal<br />
            else 0<br />
            end<br />
          ) Managers<br />
,      sum( case job<br />
            when 'SALESMAN'<br />
            then sal<br />
            else 0<br />
            end<br />
          ) salesmen<br />
from   emp<br />
group<br />
by     deptno<br />
)<br />
,   (select rownum n from emp where rownum&lt;4) dn<br />
group<br />
by     case dn.n<br />
       when 1<br />
       then  'Clerks'<br />
       when 2<br />
       then  'Managers'<br />
       when 3<br />
       then  'Salesmen'<br />
       else  null<br />
       end<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Grundy</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1170</link>
		<dc:creator>Jason Grundy</dc:creator>
		<pubDate>Tue, 23 Nov 2004 23:27:32 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1170</guid>
		<description><![CDATA[There are some good examples here but don&#039;t forget that in many circumstances an alternative approach
for magicing rows into existence is to deliberately make a cartesian join to this type of in-line view:

select rownum
from   {large table}
where  rownum &lt; {rows that you want}]]></description>
		<content:encoded><![CDATA[<p>There are some good examples here but don&#8217;t forget that in many circumstances an alternative approach<br />
for magicing rows into existence is to deliberately make a cartesian join to this type of in-line view:</p>
<p>select rownum<br />
from   {large table}<br />
where  rownum < {rows that you want}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sheetal</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1169</link>
		<dc:creator>sheetal</dc:creator>
		<pubDate>Tue, 23 Nov 2004 15:57:04 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1169</guid>
		<description><![CDATA[how do i create a matrix query to display job, salary for that job based on dept no., and total salary for that job fro all departments,
job  dept10 dept20 dept30 total
---- ------ ------ ------ -----
clerk 1300 1900    950    4150

using grouping functions]]></description>
		<content:encoded><![CDATA[<p>how do i create a matrix query to display job, salary for that job based on dept no., and total salary for that job fro all departments,<br />
job  dept10 dept20 dept30 total<br />
&#8212;- &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8211;<br />
clerk 1300 1900    950    4150</p>
<p>using grouping functions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sheetal</title>
		<link>http://technology.amis.nl/2004/11/21/making-up-records-in-sql-queries-table-functions-and-10g-model-clause/#comment-1168</link>
		<dc:creator>sheetal</dc:creator>
		<pubDate>Tue, 23 Nov 2004 15:56:41 +0000</pubDate>
		<guid isPermaLink="false">/?p=266#comment-1168</guid>
		<description><![CDATA[how do i create a matrix query to display job, salary for that job based on dept no., and total salary for that job fro all departments,
job  dept10 dept20 dept30 total
---- ------ ------ ------ -----
clerk 1300 1900]]></description>
		<content:encoded><![CDATA[<p>how do i create a matrix query to display job, salary for that job based on dept no., and total salary for that job fro all departments,<br />
job  dept10 dept20 dept30 total<br />
&#8212;- &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8211;<br />
clerk 1300 1900</p>
]]></content:encoded>
	</item>
</channel>
</rss>
