|
-
SQL query help
Hi,
I have 2 fields, customer number and lifestage (a,b,c). The lifestage can occur more than once.
How do I find customers with lifestage that have duplicates. For eg, customer 5 has 2 lifestage (a and a).
What is the simplest SQl query to acheive this?
Thanks.
Nijojo.
-
Hello
Can this help you?
SELECT customernumber, lifestage, COUNT(*) AS amount
FROM customers
GROUP BY customernumber, lifestage
Greetings
ld_be
-
Hi,
If you want only the duplicates then you only have to add the HAVING-option.
SELECT customernumber, lifestage, COUNT(lifestage) AS amount
FROM customers
GROUP BY customernumber, lifestage
HAVING COUNT(lifestage) > 1
If lifestage can be empty use count(*) instead.
Kind regards,
GC
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|