Suppose a customer table is having different columns like customer no, payments.What will be the query to select top three max payments?

SELECT customer_no, payments from customer C1
WHERE 3<=(SELECT COUNT(*) from customer C2
WHERE C1.payment <= C2.payment)

Showing Answers 1 - 13 of 13 Answers

Ravi B

  • Mar 30th, 2005
 

This is another simpler alternative: 
 
SELECT customer_no, payments FROM  
(SELECT customer_no, payments FROM  
customer C1 ORDER BY payments DESC) 
WHERE ROWNUM <4;

Manish Bhoge

  • Apr 26th, 2005
 

select distinct payments  
from  
customer A 
where 5 >= ( 
select count(*) 
from customer B  
where A.payments
order by payments descnull

Jasjeet Singh

  • Aug 10th, 2005
 

select * from (select * from customer oder by payments asc) 
where rownum<4;

  Was this answer useful?  Yes

g_sidhu

  • Feb 6th, 2008
 

SELECT ROWNUM as RANK, Customer_no, paymentsFROM (SELECT Customer_no, payments
FROM customers ORDER BY payments DESC)WHERE ROWNUM <= 3;

  Was this answer useful?  Yes

ketansnadar

  • Aug 18th, 2009
 

Situation 1 : 

If the payments and the customer no are having single records then use this 

SELECT top 3 * FROM Customer Order by Parments DESC


If the payments and the customer no are having more records and you want to sum up the payments and the retrieve then use this 

SELECT  TOP 3 [CustomerNo],SUM(Payments) FROM Customer group by [CustomerNo] order by sum(Payments) desc 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions