<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: What is ROWNUM=1 ?</title>
	<link>http://laurentschneider.com/wordpress/2007/11/what-is-rownum1.html</link>
	<description>Oracle Certified Master</description>
	<pubDate>Sun, 07 Sep 2008 07:11:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/11/what-is-rownum1.html#comment-5411</link>
		<pubDate>Tue, 20 Nov 2007 19:15:14 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/what-is-rownum1.html#comment-5411</guid>
					<description>the source is the default scott schema that can be installed with @?/rdbms/admin/utlsampl

&lt;code&gt;
CREATE TABLE DEPT
       (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,
        DNAME VARCHAR2(14) ,
        LOC VARCHAR2(13) ) ;
CREATE TABLE EMP
       (EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
        ENAME VARCHAR2(10),
        JOB VARCHAR2(9),
        MGR NUMBER(4),
        HIREDATE DATE,
        SAL NUMBER(7,2),
        COMM NUMBER(7,2),
        DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT);
INSERT INTO DEPT VALUES
        (10,'ACCOUNTING','NEW YORK');
INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');
INSERT INTO DEPT VALUES
        (30,'SALES','CHICAGO');
INSERT INTO DEPT VALUES
        (40,'OPERATIONS','BOSTON');
INSERT INTO EMP VALUES
(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
INSERT INTO EMP VALUES
(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
INSERT INTO EMP VALUES
(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
INSERT INTO EMP VALUES
(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
INSERT INTO EMP VALUES
(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);INSERT INTO EMP VALUES
(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
INSERT INTO EMP VALUES
(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
INSERT INTO EMP VALUES
(7788,'SCOTT','ANALYST',7566,to_date('13-JUL-87','dd-mm-rr')-85,3000,NULL,20);
INSERT INTO EMP VALUES
(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);INSERT INTO EMP VALUES
(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
INSERT INTO EMP VALUES
(7876,'ADAMS','CLERK',7788,to_date('13-JUL-87', 'dd-mm-rr')-51,1100,NULL,20);
INSERT INTO EMP VALUES
(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
INSERT INTO EMP VALUES
(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
INSERT INTO EMP VALUES
(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
&lt;/code&gt;

I tried with 9iR2, 10gR1, 10gR2 and 11gR1. Median does not exist in 9iR2 but PERCENTILE_CONT(.5) WITHIN GROUP (ORDER BY SAL) OVER () does provide the same result. The group by with unsorted rows is using a special optimizer access plan which is HASH GROUP BY and that appeared in 10gR2

Do not hesitate to come back with more questions :-)</description>
		<content:encoded><![CDATA[<p>the source is the default scott schema that can be installed with @?/rdbms/admin/utlsampl</p>
<p><pre><code>
CREATE TABLE DEPT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DNAME VARCHAR2(14) ,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOC VARCHAR2(13) ) ;
CREATE TABLE EMP
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENAME VARCHAR2(10),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JOB VARCHAR2(9),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MGR NUMBER(4),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HIREDATE DATE,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SAL NUMBER(7,2),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMM NUMBER(7,2),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT);
INSERT INTO DEPT VALUES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(10,&#039;ACCOUNTING&#039;,&#039;NEW YORK&#039;);
INSERT INTO DEPT VALUES (20,&#039;RESEARCH&#039;,&#039;DALLAS&#039;);
INSERT INTO DEPT VALUES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(30,&#039;SALES&#039;,&#039;CHICAGO&#039;);
INSERT INTO DEPT VALUES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(40,&#039;OPERATIONS&#039;,&#039;BOSTON&#039;);
INSERT INTO EMP VALUES
(7369,&#039;SMITH&#039;,&#039;CLERK&#039;,7902,to_date(&#039;17-12-1980&#039;,&#039;dd-mm-yyyy&#039;),800,NULL,20);
INSERT INTO EMP VALUES
(7499,&#039;ALLEN&#039;,&#039;SALESMAN&#039;,7698,to_date(&#039;20-2-1981&#039;,&#039;dd-mm-yyyy&#039;),1600,300,30);
INSERT INTO EMP VALUES
(7521,&#039;WARD&#039;,&#039;SALESMAN&#039;,7698,to_date(&#039;22-2-1981&#039;,&#039;dd-mm-yyyy&#039;),1250,500,30);
INSERT INTO EMP VALUES
(7566,&#039;JONES&#039;,&#039;MANAGER&#039;,7839,to_date(&#039;2-4-1981&#039;,&#039;dd-mm-yyyy&#039;),2975,NULL,20);
INSERT INTO EMP VALUES
(7654,&#039;MARTIN&#039;,&#039;SALESMAN&#039;,7698,to_date(&#039;28-9-1981&#039;,&#039;dd-mm-yyyy&#039;),1250,1400,30);INSERT INTO EMP VALUES
(7698,&#039;BLAKE&#039;,&#039;MANAGER&#039;,7839,to_date(&#039;1-5-1981&#039;,&#039;dd-mm-yyyy&#039;),2850,NULL,30);
INSERT INTO EMP VALUES
(7782,&#039;CLARK&#039;,&#039;MANAGER&#039;,7839,to_date(&#039;9-6-1981&#039;,&#039;dd-mm-yyyy&#039;),2450,NULL,10);
INSERT INTO EMP VALUES
(7788,&#039;SCOTT&#039;,&#039;ANALYST&#039;,7566,to_date(&#039;13-JUL-87&#039;,&#039;dd-mm-rr&#039;)-85,3000,NULL,20);
INSERT INTO EMP VALUES
(7839,&#039;KING&#039;,&#039;PRESIDENT&#039;,NULL,to_date(&#039;17-11-1981&#039;,&#039;dd-mm-yyyy&#039;),5000,NULL,10);INSERT INTO EMP VALUES
(7844,&#039;TURNER&#039;,&#039;SALESMAN&#039;,7698,to_date(&#039;8-9-1981&#039;,&#039;dd-mm-yyyy&#039;),1500,0,30);
INSERT INTO EMP VALUES
(7876,&#039;ADAMS&#039;,&#039;CLERK&#039;,7788,to_date(&#039;13-JUL-87&#039;, &#039;dd-mm-rr&#039;)-51,1100,NULL,20);
INSERT INTO EMP VALUES
(7900,&#039;JAMES&#039;,&#039;CLERK&#039;,7698,to_date(&#039;3-12-1981&#039;,&#039;dd-mm-yyyy&#039;),950,NULL,30);
INSERT INTO EMP VALUES
(7902,&#039;FORD&#039;,&#039;ANALYST&#039;,7566,to_date(&#039;3-12-1981&#039;,&#039;dd-mm-yyyy&#039;),3000,NULL,20);
INSERT INTO EMP VALUES
(7934,&#039;MILLER&#039;,&#039;CLERK&#039;,7782,to_date(&#039;23-1-1982&#039;,&#039;dd-mm-yyyy&#039;),1300,NULL,10);
</code></pre></p>
<p>I tried with 9iR2, 10gR1, 10gR2 and 11gR1. Median does not exist in 9iR2 but PERCENTILE_CONT(.5) WITHIN GROUP (ORDER BY SAL) OVER () does provide the same result. The group by with unsorted rows is using a special optimizer access plan which is HASH GROUP BY and that appeared in 10gR2</p>
<p>Do not hesitate to come back with more questions <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Brian Ballsun-Stanton</title>
		<link>http://laurentschneider.com/wordpress/2007/11/what-is-rownum1.html#comment-5410</link>
		<pubDate>Tue, 20 Nov 2007 17:44:16 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/what-is-rownum1.html#comment-5410</guid>
					<description>Interesting. Which version is this? Also, could you post the source of your sample data? This would make an excellent exercise for the performance and tuning class I'm helping with.</description>
		<content:encoded><![CDATA[<p>Interesting. Which version is this? Also, could you post the source of your sample data? This would make an excellent exercise for the performance and tuning class I&#8217;m helping with.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
