Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Query Help Please

Author  Topic 

newtosql
Starting Member

4 Posts

Posted - 2004-09-03 : 09:28:07
I have a Table called
Account

it has three field
1.Account_no
2.Customer_id
3.balance

Account_No is Unique.
Customer_Id field has multiple records for same customer_id.
balance has different values.

I want a single query that gives you a small report of
the customer_id and how many account it has.

this is the sample scenario of table

account_No==== Customer_id====balance
=======================================
123===1===100
234===1===300
345===2===8000
456===2===900
768===2===1000
999===2===10000
888===3===500
987===4===600
789===4===900
765===4===1001
555===5===2000
666===1===100
444===3===500
222===3===400


I want a single query that gives you a small report of
the customer_id and how many accounts it has.


Please Help me.

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-09-03 : 09:36:21
Select customer_Id, NumOfAccounts = count(*) From Account Group By customer_Id

Corey
Go to Top of Page

newtosql
Starting Member

4 Posts

Posted - 2004-09-03 : 09:41:39
Thank you Corey. I appreciate help.
Go to Top of Page

newtosql
Starting Member

4 Posts

Posted - 2004-09-03 : 11:08:25
How to display the customer having more than two account
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-03 : 11:12:57
Select customer_Id, NumOfAccounts = count(*)
From Account
Group By customer_Id
having count(*) > 2


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

newtosql
Starting Member

4 Posts

Posted - 2004-09-03 : 11:16:26
Thanx again.
Go to Top of Page
   

- Advertisement -