Monday, February 20, 2012

list all duplicate names (query help)

we have a table with duplicate name
1. how to list all duplicate customer names(occurring more than once), including frequency of occurrence.
2. find out how many customers have more than 2 account
Thanksselect customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1|||try this query

select cust_name , count(cust_name) from customer_table group by cust_name order by count(cust_name) desc|||Originally posted by ms_sql_dba
select customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1

Above is answer to question #1. Below is answer to question#2.

select count(*) from (
select customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1) as q|||actually, asnwer #1 lacks one line to become both #1 and #2:

select customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1
compute count(customer)

No comments:

Post a Comment