|
create table fruits (
type varchar(10) not null,
variety varchar(20) not null,
primary key(type, variety));
insert into fruits values
('apple', 'gala'),
('apple', 'fuji'),
('apple', 'limbertwig'),
('orange', 'valencia'),
('orange', 'navel'),
('pear', 'bradford'),
('pear', 'bartlett'),
('cherry', 'bing'),
('cherry', 'chelan');
第一种:
select l.type, l.variety, count(*) as num
from fruits as l
left outer join fruits as r
on l.type = r.type
and l.variety >= r.variety
group by l.type, l.variety;
第二种:
select l.type,l.variety,(select count(*) from fruits r where
r.type = l.type and r.variety <= l.variety) num
from fruits l
第三种:
oracle的查询语句
select l.type,l.variety,ROW_NUMBER() OVER(PARTITION BY l.type ORDER BY l.variety) NUM
from fruits l
由于oracle8i标准版不支持分析函数,改写成前面两种语句后,哪个的性能会快点!第二种解法属于查询语句的那种查询?
[ 本帖最后由 Helen_px 于 2007-11-14 17:22 编辑 ] |
|