boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请教oracle select top 10 from ... order by desc
相关主题
Oracle下如何能得到所有table的名字?
请教一个问题
oracle中如何查询已建立的表结构
Help about a SQL statement
请教一个SQL Query
To get the 2nd, 3rd, 4th largest value
如何在将学生成绩排序后,再加一个rank域
T-SQL Update Statement Question
给大家贡献一个fb面试的sql问题
How to list all the tables in oracle?
相关话题的讨论汇总
话题: select话题: salary话题: payroll话题: top话题: count
进入Database版参与讨论
1 (共1页)
n********6
发帖数: 1511
1
oracle 里面有TABLE: PAYROLL(ID, ..., Salary)
如果我
SELECT TOP 10 Salary
FROM PAYROLL
ORDER BY Salary Desc
能不能得到Salary最高的10条记录?
我记得TOP是随机读取的。是否有高人解释一下?
j*****n
发帖数: 1781
2
I thought TOP is only for T-SQL...
if it does, sure you will get the top 10 highest salary records, because the
result set is sorted.
n********6
发帖数: 1511
3
Ok. Since top is not available in Oracle, let me do in this way.
1. SELECT *
INTO TempTable
FROM PAYROLL
WHERE Salary = (SELECT MAX(SALARY) FROM PAYROLL)
And ID NOT IN (SELECT ID FROM TempTable)

2. SELECT Count = COUNT(*) FROM TempTable
3. Loop 2.3., when Count > 10, exit
B*****g
发帖数: 34098
4
http://www.bristle.com/Tips/SQL.htm#differences_between_oracle_and_ms_sql_server
临阵磨枪,不快也光。

【在 n********6 的大作中提到】
: Ok. Since top is not available in Oracle, let me do in this way.
: 1. SELECT *
: INTO TempTable
: FROM PAYROLL
: WHERE Salary = (SELECT MAX(SALARY) FROM PAYROLL)
: And ID NOT IN (SELECT ID FROM TempTable)
:
: 2. SELECT Count = COUNT(*) FROM TempTable
: 3. Loop 2.3., when Count > 10, exit

n********6
发帖数: 1511
5
Ok. Since top is not available in Oracle, let me do in this way.
1. CREATE TABLE TempTable
AS SELECT
FROM PAYROLL
WHERE Salary = (SELECT MAX(SALARY) FROM PAYROLL)
And ID NOT IN (SELECT ID FROM TempTable)

2. SELECT Count = COUNT(*) FROM TempTable
3. Loop 2.3., when Count > 10, exit
c**t
发帖数: 2744
6
Oracle doesn't have top n query.
select x.salary
from (
select salary, rank() over (order by salary desc null last) as rnk fro
m payroll
) x
where x.rnk < 10;
or
select x.salary from (select salary from payroll order by salary desc)
where rownum < 10;

【在 n********6 的大作中提到】
: oracle 里面有TABLE: PAYROLL(ID, ..., Salary)
: 如果我
: SELECT TOP 10 Salary
: FROM PAYROLL
: ORDER BY Salary Desc
: 能不能得到Salary最高的10条记录?
: 我记得TOP是随机读取的。是否有高人解释一下?

1 (共1页)
进入Database版参与讨论
相关主题
How to list all the tables in oracle?
help about SQL for ACCESS
难。想了一天了。大牛请进。
我也问一个sql querry的问题
请帮我看看,什么地方错了?
需要帮助 -- Oracle Query
Oracle,table有上千个column
PIVOT TABLE
问个SQL的问题
Oracle 11g坑爹还是公司DBA坑爹
相关话题的讨论汇总
话题: select话题: salary话题: payroll话题: top话题: count