初学者关于Select语句的问题(急)

[复制链接]
查看11 | 回复6 | 2006-5-9 18:02:12 | 显示全部楼层 |阅读模式
1。对一个表的数据进行排序后如何检索它的前3行数据,我用rownum试了一下不行。
2。用一条语句把一列的数据显示到一行上
例:表a,列 num

1

2

3
检索出来结果为 123 怎么实现?(这个问题以前有谁写过,不过我怎么找也找不到)
谢谢
回复

使用道具 举报

千问 | 2006-5-9 18:02:12 | 显示全部楼层
1.select * from (select col1,col2 from tab order by col1) tab where rownum 4 为什么不行啊。
2。第二个能不能说细点啊 呵呵
回复

使用道具 举报

千问 | 2006-5-9 18:02:12 | 显示全部楼层
关注decode的实现,学习
回复

使用道具 举报

千问 | 2006-5-9 18:02:12 | 显示全部楼层
up
回复

使用道具 举报

千问 | 2006-5-9 18:02:12 | 显示全部楼层
很急,哪为大哥能帮帮我啊
回复

使用道具 举报

千问 | 2006-5-9 18:02:12 | 显示全部楼层
SQL> desc table_name
Name Null? Type
----------------------------------------- -------- --------------
ID NUMBER(1)
NAME VARCHAR2(8)

SQL> select * from table_name ;
ID NAME
---------- --------
1 one
2 two
3 three
select max(decode(seq,1,name,0)) first,
max(decode(seq,2,name,0)) second,
max(decode(seq,3,name,0)) third
from ( select id,name,row_number() over ( partition by 1 order by id ) seq
from table_name
)
where seq <=3
group by 1
;
回复

使用道具 举报

千问 | 2006-5-9 18:02:12 | 显示全部楼层
http://www.itpub.net/showthread.php?threadid=96853
or
http://www.itpub.net/showthread.php?s=&threadid=96851
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行