Consider this table:
[name] [type]
"Ken Anderson" 1
"John Smith" 2
"Bill Anderson" 1
"George Anderson" 1
"Taylor Smith" 1
"Andrew Anderson" 2
"Dominic Smith" 2
and this request:
SELECT mates.type, COUNT(*) AS SmithsCount
FROM mates
WHERE mates.name LIKE "* Smith"
GROUP BY mates.type
The result should look like
[type] [SmithsCount]
1 1
2 2
What if I want to get also the number of andersons in each group? how
[type] [SmithsCount] [AndersonsCount]
1 1 3
2 2 1
And, of course, I want this to be the easiest, as it may be;) I am new to SQL, I read tutorials on W3 Schools and http://www.sql-tutorial.net/ , but there are only poorly studied basics, any "more complex" queries. Does anyone have any useful links? Thank.
source
share