现在有表T,里面有字段F1,F2,F3
其中字段 F3 有3种类型的值:1,2,3请问,如何查询T表中的F1 = 1,F1 = 2,F1 = 3时,各10条记录。
查询语句如何写?
其中字段 F3 有3种类型的值:1,2,3请问,如何查询T表中的F1 = 1,F1 = 2,F1 = 3时,各10条记录。
查询语句如何写?
解决方案 »
- oracle 的24小时制中的12:30的小时怎么取出来是00,怎么可以取出来是12
- 大表一定要建立分区吗,作用什么?
- tnsping的问题!
- 以","分解字符串怎么写函数
- oracle 8.1.7.0.0 enterprise manager 是什么?
- 求救一个简单问题
- 各位专家:ORACLE中如何解决CLOB数据的性能问题?
- 一个简单的问题!
- java.sql.SQLException: ORA-24327: 在证明一个用户之前,需要明确的连接 - (icbc/********@@192.168.0.210:1521:icbc)++++++在线。。。
- 关于oracle中的服务名的问题
- oracle9i和oracle10g能装在同一部机上吗?
- [oracle text]如何过滤word、pdf文档得到文本部分?
unoin all
select * from t where f1=2 and rownum<=10
unoin all
select * from t where f1=3 and rownum<=10
select * from (
select F1,F2, f3,row_number() over(PARTITION by F3 ORDER by f1 ) as num from T
) where num<=1
select F1,F2, f3,row_number() over(PARTITION by F3 ORDER by f1 ) as num from T
) where num<=10
select F1,F2, f3,row_number() over(PARTITION by F3 ORDER by f1 ) as num from T
) where num <=10
2楼的答案,将unoin 改成union是可以用的
就是不知道lz的F3里面的数据是否只有1、2、3,如果有上万个数的话,那2楼的方法是不行的select * from (
select F1,F2, f3,row_number() over(PARTITION by F3 ORDER by f1 ) as num from T
) where num <=10 5楼的答案可以满足比如F3有上万个不同数值的需要,但是row_number() over(PARTITION by F3 ORDER by f1 )函数的方法是,比如F3=1有15行数据,那么就会给每行记录起个标号,从1开始,当F3=2时,标号又会从1开始,问题就是如果F3=1或者F3=2时都有几十万条数据,那么我想速度会很慢期待楼下给出最佳答案
unoin all
select * from t where f1=2 and rownum<=10
unoin all
select * from t where f1=3 and rownum<=10是标准答案!
select F1,F2, f3,row_number() over(PARTITION by F3 ORDER by f1 ) as num from T
) where num <=10
对!如果F3字段只有1,2,3三个值的话用row_number()over()是能够查询出来的,不过如果F3字段还有其他
的取值的话,那么用row_number()over()的方法就不行了。