| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: does a table always need a PK?
"Christopher Browne" <cbbrowne_at_acm.org> wrote in message
news:bj5gqk$fkobb$1_at_ID-125932.news.uni-berlin.de...
> > MEDIAN is redundant:
> >
> > select sal from (
> > select rownum rn, sal from (
> > select sal from emp order by sal
> > )
> > ), (select max(rownum) rowcount from emp)
> > where rn = (rowcount+1)/2
> > union
> > select sum(sal)/2 from (
> > select rownum rn, sal from (
> > select sal from emp order by sal
> > )
> > ), (select max(rownum) rowcount from emp)
> > where mod(rowcount,2)=0 and (rn = rowcount/2 or rn = rowcount/2 + 1)
>
> What is "rownum?"
>
> I am quite sure that's not standard SQL.
OK. How about this one?
select sal from (
select sal, row_number() over (order by sal) rn,
sum(1) over () rowcount from emp
) where rn = (rowcount+1)/2
union
select sum(sal)/2 from (
select sal, row_number() over (order by sal) rn,
sum(1) over () rowcount from emp
) where mod(rowcount,2)=0 and (rn = rowcount/2 or rn = rowcount/2 + 1)
Received on Wed Sep 03 2003 - 15:19:14 CDT
![]() |
![]() |