Instruction
- Identify all actors whose last name ends in
'EN'
or'RY'
. - Group and count them by their last name.
Table: actor
col_name | col_type -------------+-------------------------- actor_id | integer first_name | text last_name | text
Sample results
last_name | count -----------+------- ALLEN | 3 BERGEN | 1
Solution postgres
SELECT
last_name,
COUNT(*)
FROM actor
WHERE last_name LIKE ('%RY')
OR last_name LIKE ('%EN')
GROUP BY last_name;
Explanation
This query is retrieving data from the "actor" table in the Postgres database. It is selecting the "last_name" column and the count of all rows for each distinct "last_name" value. The conditions in the "WHERE" clause are filtering the results to only include rows where the "last_name" ends with either "RY" or "EN". The "GROUP BY" clause is grouping the results by "last_name" so that the count is calculated for each unique "last_name" value. This query can be useful for analyzing the distribution of actors with certain last names in a database.
Copied
Expected results
Your results