top-n

What was the cost for the most expensive movie(s) in the collection? [duplicate]

ε祈祈猫儿з 提交于 2021-02-11 07:07:13
问题 This question already has answers here : Oracle SELECT TOP 10 records (6 answers) Oracle SQL - How to Retrieve highest 5 values of a column [duplicate] (5 answers) Closed 2 months ago . Hey guys I know the code to show the most expensive movie but what's the one that will show the most expensive and ones right below it. I think that's the question. This is the code I got for one movie. SELECT * FROM movie WHERE purchase_price = (SELECT MAX(purchase_price) FROM movie); 回答1: Well since your

What was the cost for the most expensive movie(s) in the collection? [duplicate]

旧巷老猫 提交于 2021-02-11 07:04:27
问题 This question already has answers here : Oracle SELECT TOP 10 records (6 answers) Oracle SQL - How to Retrieve highest 5 values of a column [duplicate] (5 answers) Closed 2 months ago . Hey guys I know the code to show the most expensive movie but what's the one that will show the most expensive and ones right below it. I think that's the question. This is the code I got for one movie. SELECT * FROM movie WHERE purchase_price = (SELECT MAX(purchase_price) FROM movie); 回答1: Well since your

What was the cost for the most expensive movie(s) in the collection? [duplicate]

末鹿安然 提交于 2021-02-11 07:03:18
问题 This question already has answers here : Oracle SELECT TOP 10 records (6 answers) Oracle SQL - How to Retrieve highest 5 values of a column [duplicate] (5 answers) Closed 2 months ago . Hey guys I know the code to show the most expensive movie but what's the one that will show the most expensive and ones right below it. I think that's the question. This is the code I got for one movie. SELECT * FROM movie WHERE purchase_price = (SELECT MAX(purchase_price) FROM movie); 回答1: Well since your

Second highest value from Oracle DB's table [duplicate]

走远了吗. 提交于 2021-02-10 03:07:20
问题 This question already has answers here : How to find the employee with the second highest salary? (5 answers) Closed last month . According to the tables: USERS (user_name, email, balance) How can I create a query that return the second highest user balance in the most efficient way ? I successes to get this record (but not by the efficient way) with the query: SELECT * FROM (SELECT us.*, ROWNUM row_num FROM (SELECT u.* FROM users u ORDER BY u.BALANCE DESC) us WHERE ROWNUM < 3) WHERE row_num

Second highest value from Oracle DB's table [duplicate]

£可爱£侵袭症+ 提交于 2021-02-10 03:06:39
问题 This question already has answers here : How to find the employee with the second highest salary? (5 answers) Closed last month . According to the tables: USERS (user_name, email, balance) How can I create a query that return the second highest user balance in the most efficient way ? I successes to get this record (but not by the efficient way) with the query: SELECT * FROM (SELECT us.*, ROWNUM row_num FROM (SELECT u.* FROM users u ORDER BY u.BALANCE DESC) us WHERE ROWNUM < 3) WHERE row_num

Second highest value from Oracle DB's table [duplicate]

て烟熏妆下的殇ゞ 提交于 2021-02-10 03:06:22
问题 This question already has answers here : How to find the employee with the second highest salary? (5 answers) Closed last month . According to the tables: USERS (user_name, email, balance) How can I create a query that return the second highest user balance in the most efficient way ? I successes to get this record (but not by the efficient way) with the query: SELECT * FROM (SELECT us.*, ROWNUM row_num FROM (SELECT u.* FROM users u ORDER BY u.BALANCE DESC) us WHERE ROWNUM < 3) WHERE row_num

SUM of only TOP 10 rows

柔情痞子 提交于 2020-12-01 09:53:52
问题 I have a query where I am only selecting the TOP 10 rows, but I have a SUM function in there that is still taking the sum of all the rows (disregarding the TOP 10). How do I get the total of only the top 10 rows? Here is my SUM function : SUM( fact.Purchase_Total_Amount) Total 回答1: Have you tried to use something like this: SELECT SUM(Whatever) FROM ( SELECT TOP(10) Whatever FROM TableName ) AS T 回答2: Use the TOP feature with a nested query SELECT SUM(innerTable.Purchase_Total_Amount) FROM

SUM of only TOP 10 rows

风流意气都作罢 提交于 2020-12-01 09:50:12
问题 I have a query where I am only selecting the TOP 10 rows, but I have a SUM function in there that is still taking the sum of all the rows (disregarding the TOP 10). How do I get the total of only the top 10 rows? Here is my SUM function : SUM( fact.Purchase_Total_Amount) Total 回答1: Have you tried to use something like this: SELECT SUM(Whatever) FROM ( SELECT TOP(10) Whatever FROM TableName ) AS T 回答2: Use the TOP feature with a nested query SELECT SUM(innerTable.Purchase_Total_Amount) FROM

Stored Procedure Maximum Pattern Match

风流意气都作罢 提交于 2020-02-03 08:25:47
问题 This is my stored procedure in Oracle: CREATE OR REPLACE PROCEDURE execute_cproc ( callnum IN VARCHAR2 , RESULT OUT VARCHAR2) AS vara_val NUMBER; varb_val NUMBER; BEGIN SELECT a_val, b_val INTO vara_val, varb_val FROM data_table WHERE callnum LIKE numberpattern || '%'; END; If CALLNUM is 03354123 then I am getting 2 results: 03354123 like 033% 03354123 like 03354% Both are true so I'm getting 2 results. How to make procedure find the longest matching only, i.e. 03354123 like 03354% ? Table :

How can i write a query in PL/SQL to find 3 maximum balance from Account table using cursor?

我只是一个虾纸丫 提交于 2020-01-25 21:37:51
问题 DECLARE CUSTID NUMBER; ANO NUMBER; BALANC NUMBER; TYP ACCOUNT.TYPE%TYPE; STATU ACCOUNT.STATUS%TYPE; CURSOR S IS SELECT * FROM ACCOUNT WHERE STATUS = 'active'; BEGIN OPEN S; FOR A IN 1..3 LOOP FETCH S DBMS_OUTPUT.PUT_LINE('CUST ID : '||CUSTID||' NO:'||ANO || ' TYPE :' || TYP || ' STATUS :' || STATU); END LOOP; CLOSE S; END; i'm trying to find 3 maximum balance on ACCOUNT table but it doesn't work ! 回答1: You don't need PL/SQL or a cursor for this: SELECT * FROM SELECT a.*, dense_rank() over