In the database query, the results are usually limited to lines with specific characteristics, such as the maximum or minimum value in specific columns. In Oracle SQL, you can use the analysis function (such as Rank (), Dense_rank (), or Row_number ()) to achieve this purpose.
for the highest value RANK () and DENSE_RANK ()Analysis functions like Rank () and Dense_rank () allocate a level to each line according to the specified sort. To retrieve the top 5 maximum value in the column, you can use the following query format:
Select *
From (from (from (from (from (from
Select
] row_number () for a certain number of lines
SELECT *
FROM (
SELECT , RANK() OVER (ORDER BY DESC) AS rnk
FROM
)
WHERE rnk
Select *
From (from (from (from (from (from
Select Non -Analysis Solution: Use Rownum
Although it is not common, you can also use the ROWNUM pseudo column to limit the results to a specific quantity. However, it should be used with caution, because Rownum is evaluated before the Order By sentence, which may lead to unpredictable results.Example: Employees with the highest salary
SELECT *
FROM (
SELECT , ROW_NUMBER() OVER (ORDER BY DESC) AS rnk
FROM
)
WHERE rnk
Select *
From (from (from (from (from (from
Select Empno, SAL, RANK () Over (Order by Sal Desc) as RNK
From Emp
Cure
Where rnk
This query allocates a numerical level for each employee based on the salary of the employee, one of which represents the highest salary employee. It then shows the top 5 employees in the order of decreased salary. Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3