If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > selecting only 10 of each

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-03, 10:10
elisabeth elisabeth is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 26
selecting only 10 of each

I want to write a query showing customer account numbers and account types.

Is there any way to pick say only 10 customer account numbers for each account type?

I just want a sample of data to be shown.

Thanks,
Beth
__________________
Beth
Reply With Quote
  #2 (permalink)  
Old 10-06-03, 10:49
cvandemaele cvandemaele is offline
Registered User
 
Join Date: Oct 2003
Location: Switzerland
Posts: 140
Hi there.

What database are you working on ?

CVM.
Reply With Quote
  #3 (permalink)  
Old 10-06-03, 10:50
elisabeth elisabeth is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 26
Quote:
Originally posted by cvandemaele
Hi there.

What database are you working on ?

CVM.
Hello there,

Oracle Version 8

thanks,
Beth
__________________
Beth
Reply With Quote
  #4 (permalink)  
Old 10-06-03, 10:58
krohit krohit is offline
Registered User
 
Join Date: Oct 2003
Posts: 12
Smile Re: selecting only 10 of each

Hi Beth,

You can query as,

Select cust_name, acct_type
From customer
Where ROWNUM <= 10;

That will give you first 10 rows of the customer table.

Thanks,
Rohit.

Quote:
Originally posted by elisabeth
I want to write a query showing customer account numbers and account types.

Is there any way to pick say only 10 customer account numbers for each account type?

I just want a sample of data to be shown.

Thanks,
Beth
Reply With Quote
  #5 (permalink)  
Old 10-06-03, 11:00
elisabeth elisabeth is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 26
Re: selecting only 10 of each

Quote:
Originally posted by krohit
Hi Beth,

You can query as,

Select cust_name, acct_type
From customer
Where ROWNUM <= 10;

That will give you first 10 rows of the customer table.

Thanks,
Rohit.
Thanks for this,
Is there any way to show the top 10 for each account type?

Beth
__________________
Beth
Reply With Quote
  #6 (permalink)  
Old 10-06-03, 11:11
cvandemaele cvandemaele is offline
Registered User
 
Join Date: Oct 2003
Location: Switzerland
Posts: 140
Try this.

Select cust_name, acct_type
From customer t1
Where t1.cust_name in
(select t2.cust_name from customer t2 where t2.acct_type = t1.acct_type and rownum <=) 10
Reply With Quote
  #7 (permalink)  
Old 10-06-03, 11:15
krohit krohit is offline
Registered User
 
Join Date: Oct 2003
Posts: 12
Smile Re: selecting only 10 of each

Hi Beth,

Try the following logic,

CURSOR acct IS
SELECT DISTINCT acct_type FROM customer;

BEGIN
FOR i IN acct LOOP
SELECT acct_no
BULK COLLECT INTO l_acct_no
FROM customer
WHERE ROWNUM <=10;
END LOOP;
END;

Thanks,
Rohit.

Quote:
Originally posted by elisabeth
I want to write a query showing customer account numbers and account types.

Is there any way to pick say only 10 customer account numbers for each account type?

I just want a sample of data to be shown.

Thanks,
Beth
Reply With Quote
  #8 (permalink)  
Old 10-06-03, 11:17
elisabeth elisabeth is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 26
Re: selecting only 10 of each

Quote:
Originally posted by krohit
Hi Beth,

You can query as,

Select cust_name, acct_type
From customer
Where ROWNUM <= 10;

That will give you first 10 rows of the customer table.

Thanks,
Rohit.
Thanks for this,
Is there any way to show the top 10 for each account type?

Beth
__________________
Beth
Reply With Quote
  #9 (permalink)  
Old 10-06-03, 20:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
the top 10 customers in each account based on what field? customer name?

rudy
Reply With Quote
  #10 (permalink)  
Old 10-15-03, 08:44
elisabeth elisabeth is offline
Registered User
 
Join Date: Jul 2003
Location: England
Posts: 26
Quote:
Originally posted by cvandemaele
Try this.

Select cust_name, acct_type
From customer t1
Where t1.cust_name in
(select t2.cust_name from customer t2 where t2.acct_type = t1.acct_type and rownum <=) 10
Thank you for these replies

I have been using this sql but unfortunately it is brining back a lot less rows than I expect.

I now want to show 10 receipt transactions for each account type.

I am using the following but it is only selecting 4 rows, I now for a fact there were 2900 cheque transactions going to 13 different account types during September.

select tran_account_no,
tran_amount_cr,
tran_date,
tran_pay_method,
tran_act_code
from transactions,accounts
where tran_account_no = acc_account_no
and tran_gtrans_type = 'R'
and tran_pay_method = 'Q'
and tran_date >= '01-SEP-2003'
and tran_date <= '30-SEP-2003'
and tran_account_no in (select acc_account_no from accounts where tran_act_code = acc_act_code and nownum <=10)
order by tran_act_code
;

The information is needed for system testing, I want a random-is selection of data.

Thanks everyone
Beth
__________________
Beth
Reply With Quote
  #11 (permalink)  
Old 10-15-03, 22:39
lsuresh lsuresh is offline
Registered User
 
Join Date: Oct 2003
Location: Chennai, India
Posts: 2
Re: selecting only 10 of each

Quote:
Originally posted by elisabeth
I want to write a query showing customer account numbers and account types.

Is there any way to pick say only 10 customer account numbers for each account type?

I just want a sample of data to be shown.

Thanks,
Beth
Dear beth,

I am suresh, i want to know which version of oracle r u using. If it is
oracle 8i then try the following query for select 10 customer account number for each account type

select * from (select customer_acc_no, row_number() over (partition by account_type order by account_type) rn
from table)
where rn <= 10

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On