Suppose the schema is like this:
First Name | Last Name | Age | ID
====================================
John Smith 18 123
John Smith 21 234
John Smith 19 123
Cathy Zhang 20 144
Cathy Zhang 20 144
Jackie Chan 35 456
Suppose I want to count the number of distinct pairs after each (first name, last name). So that the output should be:
John Smith 3
Cathy Zhang 1
Jackie Chan 1
I think I can first do:
SELECT FirstName,LastName,Age,ID,COUNT(*);
And then
SELECT FirstName,LastName,COUNT(*)
Is there a better approach?
To return the count of each distinct firstname lastname, you would use
COUNTandGROUP BY:In your above example, I think you meant Zhang to have a count of 2 though.
–EDIT
If I’m understanding your latest comment correctly, you want to also use
DISTINCT:Good luck.